0
# Device Management Errors
1
2
Error classes for Ledger device management operations including device state validation, connection issues, and hardware-specific errors.
3
4
## Capabilities
5
6
### Device Connection Errors
7
8
Errors related to establishing and maintaining device connections.
9
10
```typescript { .api }
11
const CantOpenDevice: CustomErrorFunc;
12
const DisconnectedDevice: CustomErrorFunc;
13
const DisconnectedDeviceDuringOperation: CustomErrorFunc;
14
const DeviceSocketFail: CustomErrorFunc;
15
const DeviceSocketNoBulkStatus: CustomErrorFunc;
16
```
17
18
**Usage Examples:**
19
20
```typescript
21
import {
22
CantOpenDevice,
23
DisconnectedDevice,
24
DisconnectedDeviceDuringOperation
25
} from "@ledgerhq/errors";
26
27
// Handle device opening failures
28
try {
29
await openDevice();
30
} catch (error) {
31
if (error instanceof CantOpenDevice) {
32
console.log("Unable to establish connection to device");
33
}
34
}
35
36
// Handle device disconnection
37
throw new DisconnectedDevice("Device was unplugged");
38
39
// Handle disconnection during operation
40
throw new DisconnectedDeviceDuringOperation("Device disconnected while signing transaction");
41
```
42
43
### Device State Errors
44
45
Errors related to device state validation and expected device modes.
46
47
```typescript { .api }
48
const DeviceOnDashboardExpected: CustomErrorFunc;
49
const DeviceOnDashboardUnexpected: CustomErrorFunc;
50
const DeviceInOSUExpected: CustomErrorFunc;
51
const DeviceHalted: CustomErrorFunc;
52
const UnexpectedBootloader: CustomErrorFunc;
53
const DeviceShouldStayInApp: CustomErrorFunc;
54
```
55
56
**Usage Examples:**
57
58
```typescript
59
import {
60
DeviceOnDashboardExpected,
61
DeviceOnDashboardUnexpected,
62
DeviceInOSUExpected,
63
DeviceHalted
64
} from "@ledgerhq/errors";
65
66
// Validate device is on dashboard
67
if (!isOnDashboard) {
68
throw new DeviceOnDashboardExpected("Please navigate to the dashboard on your device");
69
}
70
71
// Handle unexpected dashboard state
72
if (isOnDashboard && needsAppOpen) {
73
throw new DeviceOnDashboardUnexpected("Please open the required app on your device");
74
}
75
76
// OSU mode requirement
77
if (!isInOSUMode) {
78
throw new DeviceInOSUExpected("Device must be in OS Update mode");
79
}
80
81
// Handle halted device
82
if (deviceStatus === "halted") {
83
throw new DeviceHalted("Device is in halted state and cannot process requests");
84
}
85
```
86
87
### Device Authenticity Errors
88
89
Errors related to device authenticity and security validation.
90
91
```typescript { .api }
92
const DeviceNotGenuineError: CustomErrorFunc;
93
const GenuineCheckFailed: CustomErrorFunc;
94
const DeviceGenuineSocketEarlyClose: CustomErrorFunc;
95
const MCUNotGenuineToDashboard: CustomErrorFunc;
96
```
97
98
**Usage Examples:**
99
100
```typescript
101
import {
102
DeviceNotGenuineError,
103
GenuineCheckFailed,
104
DeviceGenuineSocketEarlyClose
105
} from "@ledgerhq/errors";
106
107
// Handle non-genuine device
108
try {
109
await verifyDeviceGenuine();
110
} catch (error) {
111
if (error instanceof DeviceNotGenuineError) {
112
console.log("Device failed authenticity check");
113
console.log("Please ensure you are using a genuine Ledger device");
114
}
115
}
116
117
// General genuine check failure
118
throw new GenuineCheckFailed("Unable to verify device authenticity");
119
120
// Socket closed during genuine check
121
throw new DeviceGenuineSocketEarlyClose("Connection closed during authenticity verification");
122
```
123
124
### Device Configuration Errors
125
126
Errors related to device naming and configuration.
127
128
```typescript { .api }
129
const DeviceNameInvalid: CustomErrorFunc;
130
const UserRefusedDeviceNameChange: CustomErrorFunc;
131
```
132
133
**Usage Examples:**
134
135
```typescript
136
import {
137
DeviceNameInvalid,
138
UserRefusedDeviceNameChange
139
} from "@ledgerhq/errors";
140
141
// Validate device name
142
function validateDeviceName(name: string) {
143
if (!name || name.length > 20 || /[^a-zA-Z0-9\s]/.test(name)) {
144
throw new DeviceNameInvalid("Device name must be 1-20 alphanumeric characters");
145
}
146
}
147
148
// Handle user refusal to change name
149
try {
150
await changeDeviceName("My Ledger");
151
} catch (error) {
152
if (error instanceof UserRefusedDeviceNameChange) {
153
console.log("User cancelled device name change");
154
}
155
}
156
```
157
158
### Hardware Reset Errors
159
160
Errors related to hardware reset operations.
161
162
```typescript { .api }
163
const HardResetFail: CustomErrorFunc;
164
```
165
166
**Usage Examples:**
167
168
```typescript
169
import { HardResetFail } from "@ledgerhq/errors";
170
171
// Handle hard reset failure
172
try {
173
await performHardReset();
174
} catch (error) {
175
throw new HardResetFail("Device hard reset operation failed");
176
}
177
```