Skip to content

Commit

Permalink
Merge pull request #6963 from LedgerHQ/bugfix/LIVE-12794-restore-tran…
Browse files Browse the repository at this point in the history
…sport-race-error

Bugfix/live 12794 restore transport race error
  • Loading branch information
aussedatlo authored May 30, 2024
2 parents 26242bd + 815ae3d commit f2ea707
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 16 deletions.
9 changes: 9 additions & 0 deletions .changeset/breezy-countries-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@ledgerhq/hw-transport": patch
"@ledgerhq/errors": patch
"ledger-live-desktop": patch
"live-mobile": patch
"@ledgerhq/live-common": patch
---

restore TransportRaceCondition instead of TransportPendingOperation that caused a breaking change
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {
UserRefusedOnDevice,
UserRefusedDeviceNameChange,
UnresponsiveDeviceError,
TransportPendingOperation,
TransportRaceCondition,
} from "@ledgerhq/errors";
import {
InstallingApp,
Expand Down Expand Up @@ -426,7 +426,7 @@ export const DeviceActionDefaultRendering = <R, H extends States, P>({
return renderInWrongAppForAccount({ t, onRetry });
}

if (unresponsive || error instanceof TransportPendingOperation) {
if (unresponsive || error instanceof TransportRaceCondition) {
return renderError({
t,
error: new UnresponsiveDeviceError(),
Expand Down
2 changes: 1 addition & 1 deletion apps/ledger-live-desktop/static/i18n/en/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5571,7 +5571,7 @@
"title": "Something went wrong. Please reconnect your device",
"description": "{{message}}"
},
"TransportPendingOperation": {
"TransportRaceCondition": {
"title": "Something went wrong. Please reconnect your device",
"description": "An action was already pending on the Ledger device. Please deny or reconnect."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ export const useUpdateFirmwareAndRestoreSettings = ({
* then either: this current fw update step is skipped or this error is ignored
* And in both cases: nothing should be displayed to the user (logs are saved).
*
* Especially: a `TransportPendingOperation` error is to be expected since we chain multiple
* Especially: a `TransportRaceCondition` error is to be expected since we chain multiple
* device actions that use different transport acquisition paradigms the action should,
* however, retry to execute and resolve the error by itself.
* There is no need to present the error to the user.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable, of } from "rxjs";
import { LockedDeviceError, TransportPendingOperation } from "@ledgerhq/errors";
import { LockedDeviceError, TransportRaceCondition } from "@ledgerhq/errors";
import { DeviceInfo, FirmwareUpdateContext } from "@ledgerhq/types-live";

import { getDeviceInfoTask, internalGetDeviceInfoTask } from "../tasks/getDeviceInfo";
Expand Down Expand Up @@ -249,9 +249,9 @@ describe("getLatestAvailableFirmwareAction", () => {
new Observable(o => {
if (count < 1) {
count++;
// Mocks the internal task, some shared error are thrown (like `TransportPendingOperation`)
// Mocks the internal task, some shared error are thrown (like `TransportRaceCondition`)
// and caught by the `sharedLogicTaskWrapper`
o.error(new TransportPendingOperation());
o.error(new TransportRaceCondition());
} else {
o.next({ type: "data", deviceInfo: aDeviceInfo });
}
Expand Down Expand Up @@ -291,7 +291,7 @@ describe("getLatestAvailableFirmwareAction", () => {
expect(error).toEqual(
expect.objectContaining({
type: "SharedError",
name: "TransportPendingOperation",
name: "TransportRaceCondition",
retrying: true,
}),
);
Expand Down
4 changes: 2 additions & 2 deletions libs/ledger-live-common/src/deviceSDK/tasks/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
CantOpenDevice,
DisconnectedDevice,
LockedDeviceError,
TransportPendingOperation,
TransportRaceCondition,
UnresponsiveDeviceError,
TransportStatusErrorClassType,
CustomErrorClassType,
Expand Down Expand Up @@ -49,7 +49,7 @@ export function sharedLogicTaskWrapper<TaskArgsType, TaskEventsType>(
error instanceof UnresponsiveDeviceError ||
error instanceof CantOpenDevice ||
error instanceof DisconnectedDevice ||
error instanceof TransportPendingOperation
error instanceof TransportRaceCondition
) {
// Emits to the action an error event so it is aware of it (for ex locked device) before retrying
const event: SharedTaskEvent = {
Expand Down
4 changes: 2 additions & 2 deletions libs/ledger-live-common/src/hw/getOnboardingStatePolling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
DeviceExtractOnboardingStateError,
DisconnectedDevice,
CantOpenDevice,
TransportPendingOperation,
TransportRaceCondition,
LockedDeviceError,
UnexpectedBootloader,
TransportExchangeTimeoutError,
Expand Down Expand Up @@ -139,7 +139,7 @@ export const isAllowedOnboardingStatePollingError = (error: unknown): boolean =>
error instanceof DisconnectedDevice ||
error instanceof DisconnectedDeviceDuringOperation ||
error instanceof CantOpenDevice ||
error instanceof TransportPendingOperation ||
error instanceof TransportRaceCondition ||
error instanceof TransportStatusError ||
// A locked device is handled as an allowed error
error instanceof LockedDeviceError)
Expand Down
2 changes: 1 addition & 1 deletion libs/ledgerjs/packages/errors/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ describe("custom errors", () => {
expect(error.statusCode).toEqual(0x6d02);
});

test.only("TransportStatusError should be mapped to a LockedDeviceError on status code 0x5515", () => {
test("TransportStatusError should be mapped to a LockedDeviceError on status code 0x5515", () => {
const error = new TransportStatusError(StatusCodes.LOCKED_DEVICE);

expect(error.name).toEqual("LockedDeviceError");
Expand Down
2 changes: 1 addition & 1 deletion libs/ledgerjs/packages/errors/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const TransportOpenUserCancelled = createCustomErrorClass("TransportOpenU
export const TransportInterfaceNotAvailable = createCustomErrorClass(
"TransportInterfaceNotAvailable",
);
export const TransportPendingOperation = createCustomErrorClass("TransportPendingOperation");
export const TransportRaceCondition = createCustomErrorClass("TransportRaceCondition");
export const TransportWebUSBGestureRequired = createCustomErrorClass(
"TransportWebUSBGestureRequired",
);
Expand Down
4 changes: 2 additions & 2 deletions libs/ledgerjs/packages/hw-transport/src/Transport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EventEmitter from "events";
import type { DeviceModel } from "@ledgerhq/devices";
import {
TransportPendingOperation,
TransportRaceCondition,
TransportError,
StatusCodes,
getAltStatusMessage,
Expand Down Expand Up @@ -339,7 +339,7 @@ export default class Transport {

if (this.exchangeBusyPromise) {
tracer.trace("Atomic exchange is already busy");
throw new TransportPendingOperation(
throw new TransportRaceCondition(
"An action was already pending on the Ledger device. Please deny or reconnect.",
);
}
Expand Down

0 comments on commit f2ea707

Please sign in to comment.