Skip to content

Commit 1ddb30c

Browse files
committed
Fix build and coverage issue
1 parent 80025a9 commit 1ddb30c

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

packages/snaps-utils/src/errors.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,28 @@ describe('WrappedSnapError', () => {
3737
});
3838
});
3939

40+
it('wraps an error without a stack', () => {
41+
const error = new Error('foo');
42+
delete error.stack;
43+
44+
const wrapped = new WrappedSnapError(error);
45+
46+
expect(wrapped).toBeInstanceOf(Error);
47+
expect(wrapped).toBeInstanceOf(WrappedSnapError);
48+
expect(wrapped.name).toBe('WrappedSnapError');
49+
expect(wrapped.message).toBe('foo');
50+
expect(wrapped.stack).toBeDefined();
51+
expect(wrapped.toJSON()).toStrictEqual({
52+
code: SNAP_ERROR_WRAPPER_CODE,
53+
message: SNAP_ERROR_WRAPPER_MESSAGE,
54+
data: {
55+
cause: {
56+
message: 'foo',
57+
},
58+
},
59+
});
60+
});
61+
4062
it('wraps a JSON-RPC error', () => {
4163
const error = new JsonRpcError(-1, 'foo');
4264
const wrapped = new WrappedSnapError(error);
@@ -278,6 +300,19 @@ describe('unwrapError', () => {
278300
expect(handled).toBe(false);
279301
});
280302

303+
it('unwraps an error without a stack', () => {
304+
const error = new Error('foo');
305+
delete error.stack;
306+
307+
const [unwrappedError, handled] = unwrapError(error);
308+
309+
expect(unwrappedError).toBeInstanceOf(Error);
310+
expect(unwrappedError.code).toBe(errorCodes.rpc.internal);
311+
expect(unwrappedError.message).toBe('foo');
312+
expect(unwrappedError.stack).toBeUndefined();
313+
expect(handled).toBe(false);
314+
});
315+
281316
it('unwraps double wrapped JSON-RPC errors', () => {
282317
const error = new JsonRpcError(-31001, 'Wrapped Snap Error', {
283318
cause: {

packages/snaps-utils/src/errors.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class WrappedSnapError extends Error {
4343

4444
this.#error = error;
4545
this.#message = message;
46-
this.#stack = getErrorStack(error);
46+
this.#stack = getErrorStack(error) ?? undefined;
4747
}
4848

4949
/**
@@ -162,11 +162,11 @@ export function isWrappedSnapError(
162162
function getJsonRpcError(
163163
code: number,
164164
message: string,
165-
stack?: string,
165+
stack?: string | null,
166166
data?: Json,
167167
) {
168168
const error = new RpcError(code, message, data);
169-
error.stack = stack;
169+
error.stack = stack ?? undefined;
170170

171171
return error;
172172
}

0 commit comments

Comments
 (0)