Skip to content

Commit

Permalink
types: Make Data type-parameter optional in JsonRpcError
Browse files Browse the repository at this point in the history
This is in order to provide backwards-compatibility with code
implemented towards v5.0.0.
  • Loading branch information
legobeat committed Aug 23, 2023
1 parent ab0ebca commit 20b7920
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
import { isPlainObject } from '@metamask/utils';
import safeStringify from 'fast-safe-stringify';

import type { DataWithOptionalCause } from './utils';
import type { DataWithOptionalCause, OptionalDataWithOptionalCause } from './utils';

Check failure on line 8 in src/classes.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Replace `·DataWithOptionalCause,·OptionalDataWithOptionalCause·` with `⏎··DataWithOptionalCause,⏎··OptionalDataWithOptionalCause,⏎`

Check failure on line 8 in src/classes.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `·DataWithOptionalCause,·OptionalDataWithOptionalCause·` with `⏎··DataWithOptionalCause,⏎··OptionalDataWithOptionalCause,⏎`
import { serializeCause } from './utils';

export type { SerializedJsonRpcError };
Expand All @@ -16,7 +16,7 @@ export type { SerializedJsonRpcError };
*
* Permits any integer error code.
*/
export class JsonRpcError<Data extends DataWithOptionalCause> extends Error {
export class JsonRpcError<Data extends OptionalDataWithOptionalCause> extends Error {

Check failure on line 19 in src/classes.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Replace `Data·extends·OptionalDataWithOptionalCause` with `⏎··Data·extends·OptionalDataWithOptionalCause,⏎`

Check failure on line 19 in src/classes.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `Data·extends·OptionalDataWithOptionalCause` with `⏎··Data·extends·OptionalDataWithOptionalCause,⏎`
public code: number;

public data?: Data;
Expand Down
10 changes: 10 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ export type DataWithOptionalCause =
cause: unknown;
};

/**
* A data object, that must be either:
*
* - A valid DataWithOptionalCause value.
* - undefined.
*/
export type OptionalDataWithOptionalCause =

Check failure on line 38 in src/utils.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (16.x)

Replace `⏎··|·undefined⏎·` with `·undefined`

Check failure on line 38 in src/utils.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Lint (18.x)

Replace `⏎··|·undefined⏎·` with `·undefined`
| undefined
| DataWithOptionalCause;

const FALLBACK_ERROR_CODE = errorCodes.rpc.internal;
const FALLBACK_MESSAGE =
'Unspecified error message. This is a bug, please report it.';
Expand Down

0 comments on commit 20b7920

Please sign in to comment.