Skip to content

Commit

Permalink
[LIVE-1108][LLD][COMMON][ERRORS] Handle LockedDeviceError correctly (#…
Browse files Browse the repository at this point in the history
…6107)

* fix(error): fix device locked error instance

Signed-off-by: jdabbech-ledger <jalil.dabbech@ledger.com>

* fix(lld): display correctly the error in update fw modal

Signed-off-by: jdabbech-ledger <jalil.dabbech@ledger.com>

---------

Signed-off-by: jdabbech-ledger <jalil.dabbech@ledger.com>
  • Loading branch information
jdabbech-ledger committed Feb 19, 2024
1 parent aeae1bd commit c377a3d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/cool-kiwis-film.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/errors": patch
---

Set prototype of locked device error in order to fix 'instanceof' check of an error
5 changes: 5 additions & 0 deletions .changeset/flat-bats-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/live-common": patch
---

Improve withDevice hook to throw LockedDeviceError
5 changes: 5 additions & 0 deletions .changeset/nervous-cobras-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"ledger-live-desktop": patch
---

Update stax display correct error on locking it
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ const DeviceCancel = ({
<ErrorDisplay
error={error}
warning={isUserRefusedFirmwareUpdate}
withExportLogs={!isUserRefusedFirmwareUpdate && !isRestoreStepRefusedOnDevice}
withExportLogs={
!isUserRefusedFirmwareUpdate && !isRestoreStepRefusedOnDevice && !isDeviceLockedError
}
/>
</UpdateFirmwareError>
);
Expand Down
6 changes: 5 additions & 1 deletion libs/ledger-live-common/src/hw/deviceAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,11 @@ export const withDevice =
},
error: error => {
tracer.trace("Job error", { error });
o.error(error);
if (error.statusCode) {
o.error(new TransportStatusError(error.statusCode));
} else {
o.error(error);
}
},
complete: () => {
o.complete();
Expand Down
3 changes: 3 additions & 0 deletions libs/ledgerjs/packages/errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ export class TransportStatusError extends Error {
this.statusCode = statusCode;
this.statusText = statusText;

Object.setPrototypeOf(this, TransportStatusError.prototype);

// Maps to a LockedDeviceError
if (canBeMappedToChildError && statusCode === StatusCodes.LOCKED_DEVICE) {
return new LockedDeviceError(message);
Expand All @@ -332,6 +334,7 @@ export class LockedDeviceError extends TransportStatusError {
this.message = message;
}
this.name = "LockedDeviceError";
Object.setPrototypeOf(this, LockedDeviceError.prototype);
}
}

Expand Down

0 comments on commit c377a3d

Please sign in to comment.