Skip to content

Commit c5e053f

Browse files
committed
types: Make Data type-parameter optional in JsonRpcError
This is in order to provide backwards-compatibility with code implemented towards v5.0.0.
1 parent b91c7e8 commit c5e053f

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

jest.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ module.exports = {
4747
global: {
4848
branches: 94.31,
4949
functions: 94.11,
50-
lines: 97.05,
51-
statements: 97.05,
50+
lines: 97.11,
51+
statements: 97.11,
5252
},
5353
},
5454

src/classes.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import {
55
} from '@metamask/utils';
66
import safeStringify from 'fast-safe-stringify';
77

8-
import { DataWithOptionalCause, serializeCause } from './utils';
8+
import type {
9+
DataWithOptionalCause,
10+
OptionalDataWithOptionalCause,
11+
} from './utils';
12+
import { serializeCause } from './utils';
913

1014
export type { SerializedJsonRpcError };
1115

@@ -15,7 +19,9 @@ export type { SerializedJsonRpcError };
1519
*
1620
* Permits any integer error code.
1721
*/
18-
export class JsonRpcError<T extends DataWithOptionalCause> extends Error {
22+
export class JsonRpcError<
23+
T extends OptionalDataWithOptionalCause,
24+
> extends Error {
1925
public code: number;
2026

2127
public data?: T;

src/utils.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ export type DataWithOptionalCause =
2727
cause: unknown;
2828
};
2929

30+
/**
31+
* A data object, that must be either:
32+
*
33+
* - A valid DataWithOptionalCause value.
34+
* - undefined.
35+
*/
36+
export type OptionalDataWithOptionalCause = undefined | DataWithOptionalCause;
37+
3038
const FALLBACK_ERROR_CODE = errorCodes.rpc.internal;
3139
const FALLBACK_MESSAGE =
3240
'Unspecified error message. This is a bug, please report it.';

0 commit comments

Comments
 (0)