Skip to content

Commit ed55cc1

Browse files
committed
chore: Add missing util
1 parent e35a9ed commit ed55cc1

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

app/controllers/perps/providers/HyperLiquidProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ export class HyperLiquidProvider implements PerpsProvider {
817817
completeInFlight();
818818
} catch (error) {
819819
// If keyring is locked, don't cache so it retries when unlocked
820-
if (ensureError(error).message === PERPS_ERROR_CODES.KEYRING_LOCKED) {
820+
if (isKeyringLockedError(error)) {
821821
this.#deps.debugLogger.log(
822822
'[ensureUnifiedAccountEnabled] Keyring locked, will retry later',
823823
);

app/controllers/perps/utils/errorUtils.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
*/
55
import { hasProperty } from '@metamask/utils';
66

7+
import { PERPS_ERROR_CODES } from '../perpsErrorCodes';
8+
79
/**
810
* Detects expected cancellation/abort errors that should not be reported to Sentry.
911
* These occur during normal navigation or view teardown when in-flight fetch requests
@@ -23,6 +25,30 @@ export function isAbortError(error: unknown): boolean {
2325
return false;
2426
}
2527

28+
/**
29+
* Detects keyring-locked errors, including SDK-wrapped errors that preserve the
30+
* original error in `cause`.
31+
*
32+
* @param error - The error to check.
33+
* @returns True if any error in the cause chain is KEYRING_LOCKED.
34+
*/
35+
export function isKeyringLockedError(error: unknown): boolean {
36+
let current: unknown = error;
37+
const seen = new Set<unknown>();
38+
39+
while (current instanceof Error && !seen.has(current)) {
40+
seen.add(current);
41+
42+
if (current.message === PERPS_ERROR_CODES.KEYRING_LOCKED) {
43+
return true;
44+
}
45+
46+
current = (current as { cause?: unknown }).cause;
47+
}
48+
49+
return false;
50+
}
51+
2652
/**
2753
* Ensures we have a proper Error object for logging.
2854
* Converts unknown/string errors to proper Error instances.

0 commit comments

Comments
 (0)