@meshconnect/uwc-injected-connector 0.28.2 → 0.28.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBhE;AA4CD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQhD;
|
|
1
|
+
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AAGzD;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBhE;AA4CD;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAQhD;AAqFD;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,CAsE/D;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAO/D"}
|
|
@@ -73,6 +73,79 @@ export function parseError(error) {
|
|
|
73
73
|
}
|
|
74
74
|
throw new WalletConnectorError(classifyWalletError(error));
|
|
75
75
|
}
|
|
76
|
+
// viem's UnknownRpcError stands in -1 for "no code it recognised"; the
|
|
77
|
+
// wallet's own code, if it sent one, is further down its cause chain.
|
|
78
|
+
const VIEM_UNKNOWN_RPC_CODE = -1;
|
|
79
|
+
const isWalletCode = (code) => typeof code === 'number' && Number.isInteger(code);
|
|
80
|
+
// A DOMException's numeric `code` is its legacy exception number (20 for
|
|
81
|
+
// AbortError), not a wallet code.
|
|
82
|
+
const isDomException = (value) => typeof DOMException === 'function' && value instanceof DOMException;
|
|
83
|
+
// One wallet-controlled field, read on its own: a getter that throws loses
|
|
84
|
+
// only that field, never a sibling branch.
|
|
85
|
+
const readField = (node, key) => {
|
|
86
|
+
try {
|
|
87
|
+
return node[key];
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The wallet's numeric EIP-1193 / JSON-RPC code, wherever a wrapper put it.
|
|
95
|
+
* Wrappers keep the wallet's error but not its code at the top: viem nests it
|
|
96
|
+
* under `cause` (TransactionExecutionError → RpcError → the provider's error)
|
|
97
|
+
* and a Solana adapter WalletError under `error`. Both are searched, level by
|
|
98
|
+
* level (`cause` before `error` within a level), so the shallowest integer
|
|
99
|
+
* code wins and a code the caller set itself is never overridden. viem's -1
|
|
100
|
+
* placeholder is not the wallet's: below the top it never counts (a bare
|
|
101
|
+
* string rejection would otherwise read as a provider code), and at the top it
|
|
102
|
+
* is kept, as before, only when nothing below it carries a code. A
|
|
103
|
+
* DOMException below the top is not a wallet and its code never counts.
|
|
104
|
+
*
|
|
105
|
+
* Bounded: MAX_CAUSE_DEPTH levels below the top, each object visited once.
|
|
106
|
+
*
|
|
107
|
+
* `topLevelCode` is the error's own `code`, already read by the caller: a
|
|
108
|
+
* wallet-controlled getter is read once.
|
|
109
|
+
*/
|
|
110
|
+
function extractWalletErrorCode(error, topLevelCode) {
|
|
111
|
+
let placeholder;
|
|
112
|
+
try {
|
|
113
|
+
if (!error || typeof error !== 'object')
|
|
114
|
+
return undefined;
|
|
115
|
+
const seen = new Set([error]);
|
|
116
|
+
let level = [error];
|
|
117
|
+
for (let depth = 0; depth <= MAX_CAUSE_DEPTH && level.length > 0; depth++) {
|
|
118
|
+
const next = [];
|
|
119
|
+
for (const node of level) {
|
|
120
|
+
const code = depth === 0 ? topLevelCode : readField(node, 'code');
|
|
121
|
+
// Below the top only: the top-level code is kept as it always was.
|
|
122
|
+
if (isWalletCode(code) && !(depth > 0 && isDomException(node))) {
|
|
123
|
+
if (code !== VIEM_UNKNOWN_RPC_CODE ||
|
|
124
|
+
readField(node, 'name') !== 'UnknownRpcError') {
|
|
125
|
+
return code;
|
|
126
|
+
}
|
|
127
|
+
if (depth === 0)
|
|
128
|
+
placeholder = code;
|
|
129
|
+
}
|
|
130
|
+
if (depth === MAX_CAUSE_DEPTH)
|
|
131
|
+
continue;
|
|
132
|
+
for (const key of ['cause', 'error']) {
|
|
133
|
+
const child = readField(node, key);
|
|
134
|
+
if (child && typeof child === 'object' && !seen.has(child)) {
|
|
135
|
+
seen.add(child);
|
|
136
|
+
next.push(child);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
level = next;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch {
|
|
144
|
+
// A hostile value (e.g. a Proxy whose prototype trap throws) leaves the
|
|
145
|
+
// code unknown; it never fails the classifier.
|
|
146
|
+
}
|
|
147
|
+
return placeholder;
|
|
148
|
+
}
|
|
76
149
|
/**
|
|
77
150
|
* Classify an error as a user rejection or an unknown error, without throwing
|
|
78
151
|
* it. {@link parseError} is this plus the throw.
|
|
@@ -90,11 +163,9 @@ export function classifyWalletError(error) {
|
|
|
90
163
|
// Read once — a wallet-controlled getter/proxy could yield inconsistent
|
|
91
164
|
// values or throw on repeated access.
|
|
92
165
|
const code = errorObj.code;
|
|
93
|
-
|
|
94
|
-
numericCode = code;
|
|
95
|
-
}
|
|
166
|
+
numericCode = extractWalletErrorCode(error, code);
|
|
96
167
|
// Check for EIP-1193 error code
|
|
97
|
-
if (
|
|
168
|
+
if (numericCode === 4001 || code === 'ACTION_REJECTED') {
|
|
98
169
|
isRejected = true;
|
|
99
170
|
}
|
|
100
171
|
// Extract message
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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AAA;QAC1D,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;IACxE,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAA;IACd,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
WalletConnectionError,
|
|
4
|
+
WalletSignTransactionError
|
|
5
|
+
} from '@solana/wallet-adapter-base'
|
|
2
6
|
import { createWalletClient, custom } from 'viem'
|
|
3
7
|
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
4
8
|
import {
|
|
@@ -19,6 +23,31 @@ const thrownBy = (input: unknown): WalletConnectorError => {
|
|
|
19
23
|
throw new Error('parseError did not throw')
|
|
20
24
|
}
|
|
21
25
|
|
|
26
|
+
// Reproduces the real path: viem's sendTransaction over an injected provider
|
|
27
|
+
// that rejects the way Trust Wallet Android does, with a bare string.
|
|
28
|
+
const viemErrorFor = async (rejection: unknown): Promise<unknown> => {
|
|
29
|
+
const from = '0x1234567890123456789012345678901234567890'
|
|
30
|
+
const client = createWalletClient({
|
|
31
|
+
account: from,
|
|
32
|
+
transport: custom({
|
|
33
|
+
request: async () => {
|
|
34
|
+
throw rejection
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
try {
|
|
39
|
+
await client.sendTransaction({
|
|
40
|
+
account: from,
|
|
41
|
+
chain: null,
|
|
42
|
+
to: '0x0987654321098765432109876543210987654321',
|
|
43
|
+
value: 1n
|
|
44
|
+
})
|
|
45
|
+
} catch (error) {
|
|
46
|
+
return error
|
|
47
|
+
}
|
|
48
|
+
throw new Error('sendTransaction did not reject')
|
|
49
|
+
}
|
|
50
|
+
|
|
22
51
|
describe('parseError (injected)', () => {
|
|
23
52
|
it('passes an already-typed WalletConnectorError through unchanged', () => {
|
|
24
53
|
const original = new WalletConnectorError({
|
|
@@ -83,31 +112,6 @@ describe('parseError (injected)', () => {
|
|
|
83
112
|
})
|
|
84
113
|
|
|
85
114
|
describe('providerReason', () => {
|
|
86
|
-
// Reproduces the real path: viem's sendTransaction over an injected provider
|
|
87
|
-
// that rejects the way Trust Wallet Android does, with a bare string.
|
|
88
|
-
const viemErrorFor = async (rejection: unknown): Promise<unknown> => {
|
|
89
|
-
const from = '0x1234567890123456789012345678901234567890'
|
|
90
|
-
const client = createWalletClient({
|
|
91
|
-
account: from,
|
|
92
|
-
transport: custom({
|
|
93
|
-
request: async () => {
|
|
94
|
-
throw rejection
|
|
95
|
-
}
|
|
96
|
-
})
|
|
97
|
-
})
|
|
98
|
-
try {
|
|
99
|
-
await client.sendTransaction({
|
|
100
|
-
account: from,
|
|
101
|
-
chain: null,
|
|
102
|
-
to: '0x0987654321098765432109876543210987654321',
|
|
103
|
-
value: 1n
|
|
104
|
-
})
|
|
105
|
-
} catch (error) {
|
|
106
|
-
return error
|
|
107
|
-
}
|
|
108
|
-
throw new Error('sendTransaction did not reject')
|
|
109
|
-
}
|
|
110
|
-
|
|
111
115
|
it('recovers a bare-string wallet rejection that viem reduces to "unknown RPC error"', async () => {
|
|
112
116
|
const err = thrownBy(await viemErrorFor('cancelled'))
|
|
113
117
|
expect(err.message).toContain('An unknown RPC error occurred.')
|
|
@@ -304,3 +308,310 @@ describe('isRequestAlreadyPending', () => {
|
|
|
304
308
|
expect(isRequestAlreadyPending(unreadable)).toBe(false)
|
|
305
309
|
})
|
|
306
310
|
})
|
|
311
|
+
|
|
312
|
+
// Wrappers keep the wallet's error but move its code off
|
|
313
|
+
// the top. Link places -32002 ("already pending") and 4001 ("rejected") by
|
|
314
|
+
// that code, so it must survive viem, the Solana adapter and the bridge.
|
|
315
|
+
describe('the wallet code below the top', () => {
|
|
316
|
+
const PENDING = "Request of type 'wallet_requestPermissions' already pending"
|
|
317
|
+
// Trust Wallet's inpage provider rejects with a real Error carrying the code
|
|
318
|
+
// (unlike MetaMask's plain object).
|
|
319
|
+
const trustStyle = (code: number, message: string) =>
|
|
320
|
+
Object.assign(new Error(message), { code })
|
|
321
|
+
|
|
322
|
+
describe('through viem (TransactionExecutionError → RpcError → wallet error)', () => {
|
|
323
|
+
it.each([
|
|
324
|
+
[
|
|
325
|
+
'a plain object, as MetaMask sends it',
|
|
326
|
+
{ code: -32002, message: PENDING }
|
|
327
|
+
],
|
|
328
|
+
[
|
|
329
|
+
'an Error with a code, as Trust Wallet sends it',
|
|
330
|
+
trustStyle(-32002, PENDING)
|
|
331
|
+
]
|
|
332
|
+
])('keeps -32002 from %s', async (_, rejection) => {
|
|
333
|
+
const raw = await viemErrorFor(rejection)
|
|
334
|
+
expect((raw as { code?: unknown }).code, 'viem drops it at the top').toBe(
|
|
335
|
+
undefined
|
|
336
|
+
)
|
|
337
|
+
const err = thrownBy(raw)
|
|
338
|
+
expect(err.code).toBe(-32002)
|
|
339
|
+
expect(err.type).toBe('unknown')
|
|
340
|
+
})
|
|
341
|
+
|
|
342
|
+
it.each([
|
|
343
|
+
[
|
|
344
|
+
'a plain object',
|
|
345
|
+
{ code: 4001, message: 'User denied transaction signature.' }
|
|
346
|
+
],
|
|
347
|
+
['an Error', trustStyle(4001, 'Transaction was rejected')]
|
|
348
|
+
])('keeps 4001 from %s and types it rejected', async (_, rejection) => {
|
|
349
|
+
const err = thrownBy(await viemErrorFor(rejection))
|
|
350
|
+
expect(err.code).toBe(4001)
|
|
351
|
+
expect(err.type).toBe('rejected')
|
|
352
|
+
})
|
|
353
|
+
|
|
354
|
+
it("reaches past viem's -1 placeholder to a code viem does not know", async () => {
|
|
355
|
+
const err = thrownBy(
|
|
356
|
+
await viemErrorFor({ code: 4999, message: 'wallet specific' })
|
|
357
|
+
)
|
|
358
|
+
expect(err.code).toBe(4999)
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
it("never reports viem's -1 placeholder as the wallet's code", async () => {
|
|
362
|
+
const err = thrownBy(await viemErrorFor('cancelled'))
|
|
363
|
+
expect(err.code).toBeUndefined()
|
|
364
|
+
expect(err.providerReason).toBe('cancelled')
|
|
365
|
+
})
|
|
366
|
+
|
|
367
|
+
it("keeps -1 as before when viem's UnknownRpcError is the error itself", async () => {
|
|
368
|
+
const client = createWalletClient({
|
|
369
|
+
transport: custom({
|
|
370
|
+
request: async () => {
|
|
371
|
+
throw 'boom'
|
|
372
|
+
}
|
|
373
|
+
})
|
|
374
|
+
})
|
|
375
|
+
const raw = await client.request({ method: 'eth_chainId' }).then(
|
|
376
|
+
() => {
|
|
377
|
+
throw new Error('request did not reject')
|
|
378
|
+
},
|
|
379
|
+
(error: unknown) => error
|
|
380
|
+
)
|
|
381
|
+
expect((raw as { name?: unknown }).name).toBe('UnknownRpcError')
|
|
382
|
+
expect(thrownBy(raw).code).toBe(-1)
|
|
383
|
+
})
|
|
384
|
+
})
|
|
385
|
+
|
|
386
|
+
describe('through the Solana wallet adapter (WalletError.error)', () => {
|
|
387
|
+
it('keeps -32002 from a WalletConnectionError', () => {
|
|
388
|
+
const err = thrownBy(
|
|
389
|
+
new WalletConnectionError(PENDING, trustStyle(-32002, PENDING))
|
|
390
|
+
)
|
|
391
|
+
expect(err.code).toBe(-32002)
|
|
392
|
+
expect(err.message).toBe(PENDING)
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
it('keeps 4001 from a WalletSignTransactionError and types it rejected', () => {
|
|
396
|
+
const err = thrownBy(
|
|
397
|
+
new WalletSignTransactionError('Signature declined', {
|
|
398
|
+
code: 4001,
|
|
399
|
+
message: 'Signature declined'
|
|
400
|
+
})
|
|
401
|
+
)
|
|
402
|
+
expect(err.code).toBe(4001)
|
|
403
|
+
expect(err.type).toBe('rejected')
|
|
404
|
+
})
|
|
405
|
+
|
|
406
|
+
it('leaves the code unknown when the adapter wrapped no wallet error', () => {
|
|
407
|
+
expect(thrownBy(new WalletConnectionError('gone')).code).toBeUndefined()
|
|
408
|
+
})
|
|
409
|
+
})
|
|
410
|
+
|
|
411
|
+
describe('through the bridge', () => {
|
|
412
|
+
// What Comlink rebuilds in the iframe: `Object.assign(new Error(message),
|
|
413
|
+
// wire)`, with `code` now on the wire (uwc-bridge-parent error-wire).
|
|
414
|
+
it('keeps the code Comlink rebuilt on the Error', () => {
|
|
415
|
+
const rebuilt = Object.assign(new Error(PENDING), {
|
|
416
|
+
name: 'Error',
|
|
417
|
+
message: PENDING,
|
|
418
|
+
code: -32002
|
|
419
|
+
})
|
|
420
|
+
expect(thrownBy(rebuilt).code).toBe(-32002)
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
it('keeps a Solana code the bridge carried as a plain `error` summary', () => {
|
|
424
|
+
const rebuilt = Object.assign(new Error(PENDING), {
|
|
425
|
+
name: 'WalletConnectionError',
|
|
426
|
+
error: { name: 'Error', message: PENDING, code: -32002 }
|
|
427
|
+
})
|
|
428
|
+
expect(thrownBy(rebuilt).code).toBe(-32002)
|
|
429
|
+
})
|
|
430
|
+
})
|
|
431
|
+
|
|
432
|
+
describe('which code wins', () => {
|
|
433
|
+
it('a 4001 below the top types rejected even when no message says so', () => {
|
|
434
|
+
const err = thrownBy({ message: 'nope', cause: { code: 4001 } })
|
|
435
|
+
expect(err.code).toBe(4001)
|
|
436
|
+
expect(err.type).toBe('rejected')
|
|
437
|
+
})
|
|
438
|
+
|
|
439
|
+
it('the top-level code, over any code below it', () => {
|
|
440
|
+
const err = thrownBy({
|
|
441
|
+
code: 4100,
|
|
442
|
+
message: 'unauthorized',
|
|
443
|
+
cause: { code: 4001 }
|
|
444
|
+
})
|
|
445
|
+
expect(err.code).toBe(4100)
|
|
446
|
+
expect(err.type).toBe('unknown')
|
|
447
|
+
})
|
|
448
|
+
|
|
449
|
+
it('the shallowest integer code, skipping a string code on the way', () => {
|
|
450
|
+
const err = thrownBy({
|
|
451
|
+
message: 'x',
|
|
452
|
+
cause: {
|
|
453
|
+
code: 'E_WRAPPED',
|
|
454
|
+
cause: { code: -32002, cause: { code: 1 } }
|
|
455
|
+
}
|
|
456
|
+
})
|
|
457
|
+
expect(err.code).toBe(-32002)
|
|
458
|
+
})
|
|
459
|
+
|
|
460
|
+
it('`cause` before `error` at the same level', () => {
|
|
461
|
+
expect(
|
|
462
|
+
thrownBy({
|
|
463
|
+
message: 'x',
|
|
464
|
+
cause: { code: 4001 },
|
|
465
|
+
error: { code: -32002 }
|
|
466
|
+
}).code
|
|
467
|
+
).toBe(4001)
|
|
468
|
+
})
|
|
469
|
+
|
|
470
|
+
it('`error` when `cause` is only a string', () => {
|
|
471
|
+
expect(
|
|
472
|
+
thrownBy({ message: 'x', cause: 'reason', error: { code: -32002 } })
|
|
473
|
+
.code
|
|
474
|
+
).toBe(-32002)
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
it('`error` when the object `cause` carries no code', () => {
|
|
478
|
+
const err = thrownBy({
|
|
479
|
+
message: 'declined',
|
|
480
|
+
cause: { message: 'context' },
|
|
481
|
+
error: { code: 4001 }
|
|
482
|
+
})
|
|
483
|
+
expect(err.code).toBe(4001)
|
|
484
|
+
expect(err.type).toBe('rejected')
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
it('a shallower `error` over a deeper `cause`', () => {
|
|
488
|
+
expect(
|
|
489
|
+
thrownBy({
|
|
490
|
+
message: 'x',
|
|
491
|
+
cause: { message: 'wrap', cause: { code: 4001 } },
|
|
492
|
+
error: { code: -32002 }
|
|
493
|
+
}).code
|
|
494
|
+
).toBe(-32002)
|
|
495
|
+
})
|
|
496
|
+
|
|
497
|
+
it("a code under `cause`'s own `error`", () => {
|
|
498
|
+
expect(
|
|
499
|
+
thrownBy({
|
|
500
|
+
message: 'x',
|
|
501
|
+
cause: { message: 'adapter', error: { code: -32002 } }
|
|
502
|
+
}).code
|
|
503
|
+
).toBe(-32002)
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
it('ACTION_REJECTED at the top still types rejected, with the code below kept', () => {
|
|
507
|
+
const err = thrownBy({
|
|
508
|
+
code: 'ACTION_REJECTED',
|
|
509
|
+
message: 'x',
|
|
510
|
+
cause: { code: 4001 }
|
|
511
|
+
})
|
|
512
|
+
expect(err.type).toBe('rejected')
|
|
513
|
+
expect(err.code).toBe(4001)
|
|
514
|
+
})
|
|
515
|
+
})
|
|
516
|
+
|
|
517
|
+
describe('limits', () => {
|
|
518
|
+
const chain = (depth: number, code: number) => {
|
|
519
|
+
let error: Record<string, unknown> = { message: 'leaf', code }
|
|
520
|
+
for (let i = 0; i < depth; i++)
|
|
521
|
+
error = { message: `level ${i}`, cause: error }
|
|
522
|
+
return error
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
it('reads a code five wrappers down', () => {
|
|
526
|
+
expect(thrownBy(chain(5, -32002)).code).toBe(-32002)
|
|
527
|
+
})
|
|
528
|
+
|
|
529
|
+
it('stops looking past five wrappers', () => {
|
|
530
|
+
expect(thrownBy(chain(6, -32002)).code).toBeUndefined()
|
|
531
|
+
})
|
|
532
|
+
|
|
533
|
+
it.each([NaN, Infinity, 1.5, '4001', null])(
|
|
534
|
+
'ignores a non-integer code below the top (%s)',
|
|
535
|
+
code => {
|
|
536
|
+
const err = thrownBy({ message: 'x', cause: { code } })
|
|
537
|
+
expect(err.code).toBeUndefined()
|
|
538
|
+
expect(err.type).toBe('unknown')
|
|
539
|
+
}
|
|
540
|
+
)
|
|
541
|
+
|
|
542
|
+
it("ignores a DOMException's legacy number below the top", () => {
|
|
543
|
+
const err = thrownBy(
|
|
544
|
+
new Error('Passkey prompt failed', {
|
|
545
|
+
cause: new DOMException('aborted', 'AbortError')
|
|
546
|
+
})
|
|
547
|
+
)
|
|
548
|
+
expect(err.code).toBeUndefined()
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
it('still reaches a wallet code below a DOMException', () => {
|
|
552
|
+
const dom = Object.assign(new DOMException('wrapped', 'AbortError'), {
|
|
553
|
+
cause: { code: -32002 }
|
|
554
|
+
})
|
|
555
|
+
expect(thrownBy(new Error('x', { cause: dom })).code).toBe(-32002)
|
|
556
|
+
})
|
|
557
|
+
|
|
558
|
+
it('keeps a top-level DOMException code as it always was', () => {
|
|
559
|
+
expect(thrownBy(new DOMException('aborted', 'AbortError')).code).toBe(20)
|
|
560
|
+
})
|
|
561
|
+
|
|
562
|
+
it('stops at a cyclic chain without a code', () => {
|
|
563
|
+
const a: Record<string, unknown> = { message: 'a' }
|
|
564
|
+
a.cause = { message: 'b', error: a }
|
|
565
|
+
expect(thrownBy(a).code).toBeUndefined()
|
|
566
|
+
})
|
|
567
|
+
|
|
568
|
+
it('survives a nested code getter that throws', () => {
|
|
569
|
+
const hostile = {}
|
|
570
|
+
Object.defineProperty(hostile, 'code', {
|
|
571
|
+
get() {
|
|
572
|
+
throw new Error('poisoned')
|
|
573
|
+
}
|
|
574
|
+
})
|
|
575
|
+
const err = thrownBy({ message: 'boom', cause: hostile })
|
|
576
|
+
expect(err.code).toBeUndefined()
|
|
577
|
+
expect(err.message).toBe('boom')
|
|
578
|
+
})
|
|
579
|
+
|
|
580
|
+
it('still reaches `error` when the `cause` getter throws', () => {
|
|
581
|
+
const node = { message: 'x', error: { code: -32002 } }
|
|
582
|
+
Object.defineProperty(node, 'cause', {
|
|
583
|
+
get() {
|
|
584
|
+
throw new Error('poisoned')
|
|
585
|
+
}
|
|
586
|
+
})
|
|
587
|
+
expect(thrownBy(node).code).toBe(-32002)
|
|
588
|
+
})
|
|
589
|
+
|
|
590
|
+
it('stops at a cycle through both `cause` and `error`', () => {
|
|
591
|
+
const a: Record<string, unknown> = { message: 'a' }
|
|
592
|
+
const b: Record<string, unknown> = { message: 'b', cause: a, error: a }
|
|
593
|
+
a.cause = b
|
|
594
|
+
a.error = b
|
|
595
|
+
expect(thrownBy(a).code).toBeUndefined()
|
|
596
|
+
})
|
|
597
|
+
|
|
598
|
+
it('stops looking past five levels on the `error` branch too', () => {
|
|
599
|
+
let error: Record<string, unknown> = { message: 'leaf', code: -32002 }
|
|
600
|
+
for (let i = 0; i < 6; i++) error = { message: `level ${i}`, error }
|
|
601
|
+
expect(thrownBy(error).code).toBeUndefined()
|
|
602
|
+
})
|
|
603
|
+
|
|
604
|
+
it('reads each wallet-controlled code once', () => {
|
|
605
|
+
let reads = 0
|
|
606
|
+
const counted = {}
|
|
607
|
+
Object.defineProperty(counted, 'code', {
|
|
608
|
+
get() {
|
|
609
|
+
reads++
|
|
610
|
+
return -32002
|
|
611
|
+
}
|
|
612
|
+
})
|
|
613
|
+
expect(thrownBy({ message: 'x', cause: counted }).code).toBe(-32002)
|
|
614
|
+
expect(reads).toBe(1)
|
|
615
|
+
})
|
|
616
|
+
})
|
|
617
|
+
})
|
package/src/utils/error-utils.ts
CHANGED
|
@@ -82,6 +82,89 @@ export function parseError(error: unknown): never {
|
|
|
82
82
|
throw new WalletConnectorError(classifyWalletError(error))
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
// viem's UnknownRpcError stands in -1 for "no code it recognised"; the
|
|
86
|
+
// wallet's own code, if it sent one, is further down its cause chain.
|
|
87
|
+
const VIEM_UNKNOWN_RPC_CODE = -1
|
|
88
|
+
|
|
89
|
+
const isWalletCode = (code: unknown): code is number =>
|
|
90
|
+
typeof code === 'number' && Number.isInteger(code)
|
|
91
|
+
|
|
92
|
+
// A DOMException's numeric `code` is its legacy exception number (20 for
|
|
93
|
+
// AbortError), not a wallet code.
|
|
94
|
+
const isDomException = (value: unknown): boolean =>
|
|
95
|
+
typeof DOMException === 'function' && value instanceof DOMException
|
|
96
|
+
|
|
97
|
+
// One wallet-controlled field, read on its own: a getter that throws loses
|
|
98
|
+
// only that field, never a sibling branch.
|
|
99
|
+
const readField = (
|
|
100
|
+
node: object,
|
|
101
|
+
key: 'name' | 'code' | 'cause' | 'error'
|
|
102
|
+
): unknown => {
|
|
103
|
+
try {
|
|
104
|
+
return (node as Record<string, unknown>)[key]
|
|
105
|
+
} catch {
|
|
106
|
+
return undefined
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* The wallet's numeric EIP-1193 / JSON-RPC code, wherever a wrapper put it.
|
|
112
|
+
* Wrappers keep the wallet's error but not its code at the top: viem nests it
|
|
113
|
+
* under `cause` (TransactionExecutionError → RpcError → the provider's error)
|
|
114
|
+
* and a Solana adapter WalletError under `error`. Both are searched, level by
|
|
115
|
+
* level (`cause` before `error` within a level), so the shallowest integer
|
|
116
|
+
* code wins and a code the caller set itself is never overridden. viem's -1
|
|
117
|
+
* placeholder is not the wallet's: below the top it never counts (a bare
|
|
118
|
+
* string rejection would otherwise read as a provider code), and at the top it
|
|
119
|
+
* is kept, as before, only when nothing below it carries a code. A
|
|
120
|
+
* DOMException below the top is not a wallet and its code never counts.
|
|
121
|
+
*
|
|
122
|
+
* Bounded: MAX_CAUSE_DEPTH levels below the top, each object visited once.
|
|
123
|
+
*
|
|
124
|
+
* `topLevelCode` is the error's own `code`, already read by the caller: a
|
|
125
|
+
* wallet-controlled getter is read once.
|
|
126
|
+
*/
|
|
127
|
+
function extractWalletErrorCode(
|
|
128
|
+
error: unknown,
|
|
129
|
+
topLevelCode: unknown
|
|
130
|
+
): number | undefined {
|
|
131
|
+
let placeholder: number | undefined
|
|
132
|
+
try {
|
|
133
|
+
if (!error || typeof error !== 'object') return undefined
|
|
134
|
+
const seen = new Set<object>([error])
|
|
135
|
+
let level: object[] = [error]
|
|
136
|
+
for (let depth = 0; depth <= MAX_CAUSE_DEPTH && level.length > 0; depth++) {
|
|
137
|
+
const next: object[] = []
|
|
138
|
+
for (const node of level) {
|
|
139
|
+
const code = depth === 0 ? topLevelCode : readField(node, 'code')
|
|
140
|
+
// Below the top only: the top-level code is kept as it always was.
|
|
141
|
+
if (isWalletCode(code) && !(depth > 0 && isDomException(node))) {
|
|
142
|
+
if (
|
|
143
|
+
code !== VIEM_UNKNOWN_RPC_CODE ||
|
|
144
|
+
readField(node, 'name') !== 'UnknownRpcError'
|
|
145
|
+
) {
|
|
146
|
+
return code
|
|
147
|
+
}
|
|
148
|
+
if (depth === 0) placeholder = code
|
|
149
|
+
}
|
|
150
|
+
if (depth === MAX_CAUSE_DEPTH) continue
|
|
151
|
+
for (const key of ['cause', 'error'] as const) {
|
|
152
|
+
const child = readField(node, key)
|
|
153
|
+
if (child && typeof child === 'object' && !seen.has(child)) {
|
|
154
|
+
seen.add(child)
|
|
155
|
+
next.push(child)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
level = next
|
|
160
|
+
}
|
|
161
|
+
} catch {
|
|
162
|
+
// A hostile value (e.g. a Proxy whose prototype trap throws) leaves the
|
|
163
|
+
// code unknown; it never fails the classifier.
|
|
164
|
+
}
|
|
165
|
+
return placeholder
|
|
166
|
+
}
|
|
167
|
+
|
|
85
168
|
/**
|
|
86
169
|
* Classify an error as a user rejection or an unknown error, without throwing
|
|
87
170
|
* it. {@link parseError} is this plus the throw.
|
|
@@ -101,12 +184,10 @@ export function classifyWalletError(error: unknown): WalletError {
|
|
|
101
184
|
// Read once — a wallet-controlled getter/proxy could yield inconsistent
|
|
102
185
|
// values or throw on repeated access.
|
|
103
186
|
const code = errorObj.code
|
|
104
|
-
|
|
105
|
-
numericCode = code
|
|
106
|
-
}
|
|
187
|
+
numericCode = extractWalletErrorCode(error, code)
|
|
107
188
|
|
|
108
189
|
// Check for EIP-1193 error code
|
|
109
|
-
if (
|
|
190
|
+
if (numericCode === 4001 || code === 'ACTION_REJECTED') {
|
|
110
191
|
isRejected = true
|
|
111
192
|
}
|
|
112
193
|
|