Socket
Socket
Sign inDemoInstall

@metamask/rpc-errors

Package Overview
Dependencies
Maintainers
8
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@metamask/rpc-errors - npm Package Compare versions

Comparing version 5.0.0 to 5.1.0

CHANGELOG.md

4

dist/__fixtures__/errors.d.ts

@@ -40,4 +40,4 @@ export declare const dummyData: {

};
export declare const validError2: import("..").JsonRpcError<import("@metamask/utils").Json>;
export declare const validError3: import("..").JsonRpcError<import("@metamask/utils").Json>;
export declare const validError2: import("..").JsonRpcError<import("..").DataWithOptionalCause>;
export declare const validError3: import("..").JsonRpcError<import("..").DataWithOptionalCause>;
export declare const validError4: import("..").JsonRpcError<{

@@ -44,0 +44,0 @@ foo: string;

@@ -1,3 +0,4 @@

import { Json, JsonRpcError as SerializedJsonRpcError } from '@metamask/utils';
export { SerializedJsonRpcError };
import { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils';
import { DataWithOptionalCause } from './utils';
export type { SerializedJsonRpcError };
/**

@@ -9,3 +10,3 @@ * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors

*/
export declare class JsonRpcError<T extends Json> extends Error {
export declare class JsonRpcError<T extends DataWithOptionalCause> extends Error {
code: number;

@@ -32,3 +33,3 @@ data?: T;

*/
export declare class EthereumProviderError<T extends Json> extends JsonRpcError<T> {
export declare class EthereumProviderError<T extends DataWithOptionalCause> extends JsonRpcError<T> {
/**

@@ -35,0 +36,0 @@ * Create an Ethereum Provider JSON-RPC error.

@@ -7,3 +7,5 @@ "use strict";

exports.EthereumProviderError = exports.JsonRpcError = void 0;
const utils_1 = require("@metamask/utils");
const fast_safe_stringify_1 = __importDefault(require("fast-safe-stringify"));
const utils_2 = require("./utils");
/**

@@ -40,3 +42,9 @@ * Error subclass implementing JSON RPC 2.0 errors and Ethereum RPC errors

if (this.data !== undefined) {
// `this.data` is not guaranteed to be a plain object, but this simplifies
// the type guard below. We can safely cast it because we know it's a
// JSON-serializable value.
serialized.data = this.data;
if ((0, utils_1.isPlainObject)(this.data)) {
serialized.data.cause = (0, utils_2.serializeCause)(this.data.cause);
}
}

@@ -43,0 +51,0 @@ if (this.stack) {

@@ -26,2 +26,3 @@ "use strict";

};
/* eslint-disable @typescript-eslint/naming-convention */
exports.errorValues = {

@@ -93,2 +94,3 @@ '-32700': {

};
/* eslint-enable @typescript-eslint/naming-convention */
//# sourceMappingURL=error-constants.js.map

@@ -1,12 +0,12 @@

import { Json } from '@metamask/utils';
import { JsonRpcError, EthereumProviderError } from './classes';
type EthereumErrorOptions<T extends Json> = {
import { DataWithOptionalCause } from './utils';
type EthereumErrorOptions<T extends DataWithOptionalCause> = {
message?: string;
data?: T;
};
type ServerErrorOptions<T extends Json> = {
type ServerErrorOptions<T extends DataWithOptionalCause> = {
code: number;
} & EthereumErrorOptions<T>;
type CustomErrorArg<T extends Json> = ServerErrorOptions<T>;
type JsonRpcErrorsArg<T extends Json> = EthereumErrorOptions<T> | string;
type CustomErrorArg<T extends DataWithOptionalCause> = ServerErrorOptions<T>;
type JsonRpcErrorsArg<T extends DataWithOptionalCause> = EthereumErrorOptions<T> | string;
export declare const rpcErrors: {

@@ -19,3 +19,3 @@ /**

*/
parse: <T extends Json>(arg?: JsonRpcErrorsArg<T> | undefined) => JsonRpcError<T>;
parse: <T extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T> | undefined) => JsonRpcError<T>;
/**

@@ -27,3 +27,3 @@ * Get a JSON RPC 2.0 Invalid Request (-32600) error.

*/
invalidRequest: <T_1 extends Json>(arg?: JsonRpcErrorsArg<T_1> | undefined) => JsonRpcError<T_1>;
invalidRequest: <T_1 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_1> | undefined) => JsonRpcError<T_1>;
/**

@@ -35,3 +35,3 @@ * Get a JSON RPC 2.0 Invalid Params (-32602) error.

*/
invalidParams: <T_2 extends Json>(arg?: JsonRpcErrorsArg<T_2> | undefined) => JsonRpcError<T_2>;
invalidParams: <T_2 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_2> | undefined) => JsonRpcError<T_2>;
/**

@@ -43,3 +43,3 @@ * Get a JSON RPC 2.0 Method Not Found (-32601) error.

*/
methodNotFound: <T_3 extends Json>(arg?: JsonRpcErrorsArg<T_3> | undefined) => JsonRpcError<T_3>;
methodNotFound: <T_3 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_3> | undefined) => JsonRpcError<T_3>;
/**

@@ -51,3 +51,3 @@ * Get a JSON RPC 2.0 Internal (-32603) error.

*/
internal: <T_4 extends Json>(arg?: JsonRpcErrorsArg<T_4> | undefined) => JsonRpcError<T_4>;
internal: <T_4 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_4> | undefined) => JsonRpcError<T_4>;
/**

@@ -61,3 +61,3 @@ * Get a JSON RPC 2.0 Server error.

*/
server: <T_5 extends Json>(opts: ServerErrorOptions<T_5>) => JsonRpcError<T_5>;
server: <T_5 extends DataWithOptionalCause>(opts: ServerErrorOptions<T_5>) => JsonRpcError<T_5>;
/**

@@ -69,3 +69,3 @@ * Get an Ethereum JSON RPC Invalid Input (-32000) error.

*/
invalidInput: <T_6 extends Json>(arg?: JsonRpcErrorsArg<T_6> | undefined) => JsonRpcError<T_6>;
invalidInput: <T_6 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_6> | undefined) => JsonRpcError<T_6>;
/**

@@ -77,3 +77,3 @@ * Get an Ethereum JSON RPC Resource Not Found (-32001) error.

*/
resourceNotFound: <T_7 extends Json>(arg?: JsonRpcErrorsArg<T_7> | undefined) => JsonRpcError<T_7>;
resourceNotFound: <T_7 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_7> | undefined) => JsonRpcError<T_7>;
/**

@@ -85,3 +85,3 @@ * Get an Ethereum JSON RPC Resource Unavailable (-32002) error.

*/
resourceUnavailable: <T_8 extends Json>(arg?: JsonRpcErrorsArg<T_8> | undefined) => JsonRpcError<T_8>;
resourceUnavailable: <T_8 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_8> | undefined) => JsonRpcError<T_8>;
/**

@@ -93,3 +93,3 @@ * Get an Ethereum JSON RPC Transaction Rejected (-32003) error.

*/
transactionRejected: <T_9 extends Json>(arg?: JsonRpcErrorsArg<T_9> | undefined) => JsonRpcError<T_9>;
transactionRejected: <T_9 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_9> | undefined) => JsonRpcError<T_9>;
/**

@@ -101,3 +101,3 @@ * Get an Ethereum JSON RPC Method Not Supported (-32004) error.

*/
methodNotSupported: <T_10 extends Json>(arg?: JsonRpcErrorsArg<T_10> | undefined) => JsonRpcError<T_10>;
methodNotSupported: <T_10 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_10> | undefined) => JsonRpcError<T_10>;
/**

@@ -109,3 +109,3 @@ * Get an Ethereum JSON RPC Limit Exceeded (-32005) error.

*/
limitExceeded: <T_11 extends Json>(arg?: JsonRpcErrorsArg<T_11> | undefined) => JsonRpcError<T_11>;
limitExceeded: <T_11 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_11> | undefined) => JsonRpcError<T_11>;
};

@@ -119,3 +119,3 @@ export declare const providerErrors: {

*/
userRejectedRequest: <T extends Json>(arg?: JsonRpcErrorsArg<T> | undefined) => EthereumProviderError<T>;
userRejectedRequest: <T extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T> | undefined) => EthereumProviderError<T>;
/**

@@ -127,3 +127,3 @@ * Get an Ethereum Provider Unauthorized (4100) error.

*/
unauthorized: <T_1 extends Json>(arg?: JsonRpcErrorsArg<T_1> | undefined) => EthereumProviderError<T_1>;
unauthorized: <T_1 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_1> | undefined) => EthereumProviderError<T_1>;
/**

@@ -135,3 +135,3 @@ * Get an Ethereum Provider Unsupported Method (4200) error.

*/
unsupportedMethod: <T_2 extends Json>(arg?: JsonRpcErrorsArg<T_2> | undefined) => EthereumProviderError<T_2>;
unsupportedMethod: <T_2 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_2> | undefined) => EthereumProviderError<T_2>;
/**

@@ -143,3 +143,3 @@ * Get an Ethereum Provider Not Connected (4900) error.

*/
disconnected: <T_3 extends Json>(arg?: JsonRpcErrorsArg<T_3> | undefined) => EthereumProviderError<T_3>;
disconnected: <T_3 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_3> | undefined) => EthereumProviderError<T_3>;
/**

@@ -151,3 +151,3 @@ * Get an Ethereum Provider Chain Not Connected (4901) error.

*/
chainDisconnected: <T_4 extends Json>(arg?: JsonRpcErrorsArg<T_4> | undefined) => EthereumProviderError<T_4>;
chainDisconnected: <T_4 extends DataWithOptionalCause>(arg?: JsonRpcErrorsArg<T_4> | undefined) => EthereumProviderError<T_4>;
/**

@@ -159,4 +159,4 @@ * Get a custom Ethereum Provider error.

*/
custom: <T_5 extends Json>(opts: CustomErrorArg<T_5>) => EthereumProviderError<T_5>;
custom: <T_5 extends DataWithOptionalCause>(opts: CustomErrorArg<T_5>) => EthereumProviderError<T_5>;
};
export {};

@@ -5,4 +5,4 @@ "use strict";

const classes_1 = require("./classes");
const error_constants_1 = require("./error-constants");
const utils_1 = require("./utils");
const error_constants_1 = require("./error-constants");
exports.rpcErrors = {

@@ -177,3 +177,3 @@ /**

const [message, data] = parseOpts(arg);
return new classes_1.JsonRpcError(code, message || (0, utils_1.getMessageFromCode)(code), data);
return new classes_1.JsonRpcError(code, message ?? (0, utils_1.getMessageFromCode)(code), data);
}

@@ -189,3 +189,3 @@ /**

const [message, data] = parseOpts(arg);
return new classes_1.EthereumProviderError(code, message || (0, utils_1.getMessageFromCode)(code), data);
return new classes_1.EthereumProviderError(code, message ?? (0, utils_1.getMessageFromCode)(code), data);
}

@@ -208,3 +208,3 @@ /**

}
return [message || undefined, data];
return [message ?? undefined, data];
}

@@ -211,0 +211,0 @@ }

@@ -1,5 +0,5 @@

import { JsonRpcError, EthereumProviderError } from './classes';
import { serializeError, getMessageFromCode } from './utils';
import { rpcErrors, providerErrors } from './errors';
import { errorCodes } from './error-constants';
export { errorCodes, rpcErrors, providerErrors, JsonRpcError, EthereumProviderError, serializeError, getMessageFromCode, };
export { JsonRpcError, EthereumProviderError } from './classes';
export { serializeCause, serializeError, getMessageFromCode } from './utils';
export type { DataWithOptionalCause } from './utils';
export { rpcErrors, providerErrors } from './errors';
export { errorCodes } from './error-constants';
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMessageFromCode = exports.serializeError = exports.EthereumProviderError = exports.JsonRpcError = exports.providerErrors = exports.rpcErrors = exports.errorCodes = void 0;
const classes_1 = require("./classes");
exports.errorCodes = exports.providerErrors = exports.rpcErrors = exports.getMessageFromCode = exports.serializeError = exports.serializeCause = exports.EthereumProviderError = exports.JsonRpcError = void 0;
var classes_1 = require("./classes");
Object.defineProperty(exports, "JsonRpcError", { enumerable: true, get: function () { return classes_1.JsonRpcError; } });
Object.defineProperty(exports, "EthereumProviderError", { enumerable: true, get: function () { return classes_1.EthereumProviderError; } });
const utils_1 = require("./utils");
var utils_1 = require("./utils");
Object.defineProperty(exports, "serializeCause", { enumerable: true, get: function () { return utils_1.serializeCause; } });
Object.defineProperty(exports, "serializeError", { enumerable: true, get: function () { return utils_1.serializeError; } });
Object.defineProperty(exports, "getMessageFromCode", { enumerable: true, get: function () { return utils_1.getMessageFromCode; } });
const errors_1 = require("./errors");
var errors_1 = require("./errors");
Object.defineProperty(exports, "rpcErrors", { enumerable: true, get: function () { return errors_1.rpcErrors; } });
Object.defineProperty(exports, "providerErrors", { enumerable: true, get: function () { return errors_1.providerErrors; } });
const error_constants_1 = require("./error-constants");
var error_constants_1 = require("./error-constants");
Object.defineProperty(exports, "errorCodes", { enumerable: true, get: function () { return error_constants_1.errorCodes; } });
//# sourceMappingURL=index.js.map

@@ -1,2 +0,13 @@

import { JsonRpcError as SerializedJsonRpcError } from '@metamask/utils';
import { Json, JsonRpcError as SerializedJsonRpcError } from '@metamask/utils';
/**
* A data object, that must be either:
*
* - A JSON-serializable object.
* - An object with a `cause` property that is an `Error` instance, and any
* other properties that are JSON-serializable.
*/
export type DataWithOptionalCause = Json | {
[key: string]: Json | Error;
cause: Error;
};
export declare const JSON_RPC_SERVER_ERROR_MESSAGE = "Unspecified server error.";

@@ -39,1 +50,8 @@ /**

}): SerializedJsonRpcError;
/**
* Serializes an unknown error to be used as the `cause` in a fallback error.
*
* @param error - The unknown error.
* @returns A JSON-serializable object containing as much information about the original error as possible.
*/
export declare function serializeCause(error: unknown): Json;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeError = exports.isValidCode = exports.getMessageFromCode = exports.JSON_RPC_SERVER_ERROR_MESSAGE = void 0;
exports.serializeCause = exports.serializeError = exports.isValidCode = exports.getMessageFromCode = exports.JSON_RPC_SERVER_ERROR_MESSAGE = void 0;
const utils_1 = require("@metamask/utils");

@@ -132,2 +132,3 @@ const error_constants_1 = require("./error-constants");

}
exports.serializeCause = serializeCause;
/**

@@ -134,0 +135,0 @@ * Extracts all JSON-serializable properties from an object.

{
"name": "@metamask/rpc-errors",
"version": "5.0.0",
"version": "5.1.0",
"description": "Ethereum RPC and Provider errors.",

@@ -45,14 +45,14 @@ "keywords": [

"@metamask/auto-changelog": "^2.3.0",
"@metamask/eslint-config": "^10.0.0",
"@metamask/eslint-config-jest": "^10.0.0",
"@metamask/eslint-config-nodejs": "^10.0.0",
"@metamask/eslint-config-typescript": "^10.0.0",
"@metamask/eslint-config": "^11.1.0",
"@metamask/eslint-config-jest": "^11.1.0",
"@metamask/eslint-config-nodejs": "^11.1.0",
"@metamask/eslint-config-typescript": "^11.1.0",
"@types/jest": "^28.1.6",
"@typescript-eslint/eslint-plugin": "^5.33.1",
"@typescript-eslint/parser": "^5.33.1",
"eslint": "^8.22.0",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^26.8.3",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-jest": "^27.1.5",
"eslint-plugin-jsdoc": "^39.6.2",
"eslint-plugin-node": "^11.1.0",

@@ -77,2 +77,2 @@ "eslint-plugin-prettier": "^4.2.1",

}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc