From 693e0d229da5a6e598f9371c299b3c20db74b767 Mon Sep 17 00:00:00 2001 From: "Valentin D. Pinkman" Date: Thu, 16 Jan 2025 17:05:46 +0100 Subject: [PATCH] tmp fix errors on ubuntu --- .../src/deviceSDK/transports/core.ts | 10 ++++++++++ libs/ledger-live-common/src/hw/deviceAccess.ts | 11 +++++++++++ libs/ledgerjs/packages/errors/src/index.ts | 8 ++++++++ libs/live-dmk/.unimportedrc.json | 2 +- libs/live-dmk/src/config/activeDeviceSession.ts | 2 +- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/ledger-live-common/src/deviceSDK/transports/core.ts b/libs/ledger-live-common/src/deviceSDK/transports/core.ts index 2dc535492e86..5c342ad853ef 100644 --- a/libs/ledger-live-common/src/deviceSDK/transports/core.ts +++ b/libs/ledger-live-common/src/deviceSDK/transports/core.ts @@ -6,6 +6,7 @@ import { BluetoothRequired, CantOpenDevice, DeviceHalted, + DeviceMangementKitError, FirmwareOrAppUpdateRequired, PairingFailed, PeerRemovedPairing, @@ -266,6 +267,15 @@ const initialErrorRemapping = (error: unknown, context?: TraceContext) => { } } + // HANDLE DMK ERRORS + if (error && typeof error === "object" && "_tag" in error) { + const message = + "originalError" in error && typeof error.originalError === "object" + ? ((error.originalError as Error).message as string) + : (error._tag as string); + mappedError = new DeviceMangementKitError(error._tag as string, message); + } + trace({ type: LOG_TYPE, message: `Initial error remapping: ${error}`, diff --git a/libs/ledger-live-common/src/hw/deviceAccess.ts b/libs/ledger-live-common/src/hw/deviceAccess.ts index 7baa4d56ebd5..345fd77266df 100644 --- a/libs/ledger-live-common/src/hw/deviceAccess.ts +++ b/libs/ledger-live-common/src/hw/deviceAccess.ts @@ -14,6 +14,7 @@ import { DeviceHalted, PeerRemovedPairing, PairingFailed, + DeviceMangementKitError, } from "@ledgerhq/errors"; import { LocalTracer, TraceContext, trace } from "@ledgerhq/logs"; import { getEnv } from "@ledgerhq/live-env"; @@ -32,6 +33,15 @@ const initialErrorRemapping = (error: unknown, context?: TraceContext) => { } } + // HANDLE DMK ERRORS + if (error && typeof error === "object" && "_tag" in error) { + const message = + "originalError" in error && typeof error.originalError === "object" + ? ((error.originalError as Error).message as string) + : (error._tag as string); + mappedError = new DeviceMangementKitError(error._tag as string, message); + } + trace({ type: LOG_TYPE, message: `Initial error remapping: ${error}`, @@ -46,6 +56,7 @@ let errorRemapping = e => throwError(() => e); export const setErrorRemapping = (f: (arg0: Error) => Observable): void => { errorRemapping = f; }; + const never = new Promise(() => {}); /** diff --git a/libs/ledgerjs/packages/errors/src/index.ts b/libs/ledgerjs/packages/errors/src/index.ts index 992aed2c31ce..6ad0e6baf8ff 100644 --- a/libs/ledgerjs/packages/errors/src/index.ts +++ b/libs/ledgerjs/packages/errors/src/index.ts @@ -378,6 +378,14 @@ export class LockedDeviceError extends TransportStatusError { } } +export class DeviceMangementKitError extends Error { + constructor(name: string, message: string) { + super(message); + this.name = name; + Object.setPrototypeOf(this, DeviceMangementKitError.prototype); + } +} + // Represents the type of the class TransportStatusError and its children export type TransportStatusErrorClassType = typeof TransportStatusError | typeof LockedDeviceError; diff --git a/libs/live-dmk/.unimportedrc.json b/libs/live-dmk/.unimportedrc.json index e66efc9e8253..ba8c2dd0a186 100644 --- a/libs/live-dmk/.unimportedrc.json +++ b/libs/live-dmk/.unimportedrc.json @@ -1,5 +1,5 @@ { - "entry": ["src/index.tsx"], + "entry": ["src/index.ts"], "ignorePatterns": ["**/node_modules/**", "**/*.test.{ts,tsx}"], "ignoreUnused": ["react-dom"] } diff --git a/libs/live-dmk/src/config/activeDeviceSession.ts b/libs/live-dmk/src/config/activeDeviceSession.ts index d22ba69fa139..3e7c8a2fea32 100644 --- a/libs/live-dmk/src/config/activeDeviceSession.ts +++ b/libs/live-dmk/src/config/activeDeviceSession.ts @@ -1,5 +1,5 @@ import { BehaviorSubject } from "rxjs"; -import { DeviceManagementKitTransport } from "src/transport/DeviceManagementKitTransport"; +import { DeviceManagementKitTransport } from "../transport/DeviceManagementKitTransport"; export const activeDeviceSessionSubject: BehaviorSubject<{ sessionId: string;