diff --git a/packages/errors/.npmignore b/packages/errors/.npmignore deleted file mode 100644 index 71e16cd2e..000000000 --- a/packages/errors/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -# We do not need the TypeScipt source in deployments -tsconfig.json -src.ts/ - -# To run tests, checkout GitHub -tests/ -tsconfig.tsbuildinfo diff --git a/packages/errors/LICENSE.md b/packages/errors/LICENSE.md deleted file mode 100644 index 989e34a72..000000000 --- a/packages/errors/LICENSE.md +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2019 Richard Moore - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/packages/errors/README.md b/packages/errors/README.md deleted file mode 100644 index 9ebc5c444..000000000 --- a/packages/errors/README.md +++ /dev/null @@ -1,6 +0,0 @@ -Error Generalizations and Utilities -=================================== - -**DEPRECATED** - -Please use `@ethersproject/logger` instead. diff --git a/packages/errors/lib.esm/_version.d.ts b/packages/errors/lib.esm/_version.d.ts deleted file mode 100644 index 6fc5332c8..000000000 --- a/packages/errors/lib.esm/_version.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const version = "errors/5.0.1"; diff --git a/packages/errors/lib.esm/_version.js b/packages/errors/lib.esm/_version.js deleted file mode 100644 index 97dd69b28..000000000 --- a/packages/errors/lib.esm/_version.js +++ /dev/null @@ -1 +0,0 @@ -export const version = "errors/5.0.1"; diff --git a/packages/errors/lib.esm/index.d.ts b/packages/errors/lib.esm/index.d.ts deleted file mode 100644 index 1890f1255..000000000 --- a/packages/errors/lib.esm/index.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -export declare const UNKNOWN_ERROR = "UNKNOWN_ERROR"; -export declare const NOT_IMPLEMENTED = "NOT_IMPLEMENTED"; -export declare const UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION"; -export declare const NETWORK_ERROR = "NETWORK_ERROR"; -export declare const SERVER_ERROR = "SERVER_ERROR"; -export declare const TIMEOUT = "TIMEOUT"; -export declare const BUFFER_OVERRUN = "BUFFER_OVERRUN"; -export declare const NUMERIC_FAULT = "NUMERIC_FAULT"; -export declare const MISSING_NEW = "MISSING_NEW"; -export declare const INVALID_ARGUMENT = "INVALID_ARGUMENT"; -export declare const MISSING_ARGUMENT = "MISSING_ARGUMENT"; -export declare const UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT"; -export declare const CALL_EXCEPTION = "CALL_EXCEPTION"; -export declare const INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS"; -export declare const NONCE_EXPIRED = "NONCE_EXPIRED"; -export declare const REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED"; -export declare const UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT"; -export declare function setCensorship(censorship: boolean, permanent?: boolean): void; -export declare function makeError(message: string, code: string, params: any): Error; -export declare function throwError(message: string, code: string, params: any): never; -export declare function throwArgumentError(message: string, name: string, value: any): never; -export declare function checkArgumentCount(count: number, expectedCount: number, suffix?: string): void; -export declare function checkNew(target: any, kind: any): void; -export declare function checkAbstract(target: any, kind: any): void; -export declare function checkNormalize(): void; -export declare function checkSafeUint53(value: number, message?: string): void; -export declare function setLogLevel(logLevel: string): void; -export declare function warn(...args: Array): void; -export declare function info(...args: Array): void; diff --git a/packages/errors/lib.esm/index.js b/packages/errors/lib.esm/index.js deleted file mode 100644 index 202e36b09..000000000 --- a/packages/errors/lib.esm/index.js +++ /dev/null @@ -1,245 +0,0 @@ -"use strict"; -//import { version } from "./_version"; -const version = "@TODO"; -/////////////////// -// Generic Errors -// Unknown Error -export const UNKNOWN_ERROR = "UNKNOWN_ERROR"; -// Not Implemented -export const NOT_IMPLEMENTED = "NOT_IMPLEMENTED"; -// Unsupported Operation -// - operation -export const UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION"; -// Network Error (i.e. Ethereum Network, such as an invalid chain ID) -export const NETWORK_ERROR = "NETWORK_ERROR"; -// Some sort of bad response from the server -export const SERVER_ERROR = "SERVER_ERROR"; -// Timeout -export const TIMEOUT = "TIMEOUT"; -/////////////////// -// Operational Errors -// Buffer Overrun -export const BUFFER_OVERRUN = "BUFFER_OVERRUN"; -// Numeric Fault -// - operation: the operation being executed -// - fault: the reason this faulted -export const NUMERIC_FAULT = "NUMERIC_FAULT"; -/////////////////// -// Argument Errors -// Missing new operator to an object -// - name: The name of the class -export const MISSING_NEW = "MISSING_NEW"; -// Invalid argument (e.g. value is incompatible with type) to a function: -// - argument: The argument name that was invalid -// - value: The value of the argument -export const INVALID_ARGUMENT = "INVALID_ARGUMENT"; -// Missing argument to a function: -// - count: The number of arguments received -// - expectedCount: The number of arguments expected -export const MISSING_ARGUMENT = "MISSING_ARGUMENT"; -// Too many arguments -// - count: The number of arguments received -// - expectedCount: The number of arguments expected -export const UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT"; -/////////////////// -// Blockchain Errors -// Call exception -// - transaction: the transaction -// - address?: the contract address -// - args?: The arguments passed into the function -// - method?: The Solidity method signature -// - errorSignature?: The EIP848 error signature -// - errorArgs?: The EIP848 error parameters -// - reason: The reason (only for EIP848 "Error(string)") -export const CALL_EXCEPTION = "CALL_EXCEPTION"; -// Insufficien funds (< value + gasLimit * gasPrice) -// - transaction: the transaction attempted -export const INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS"; -// Nonce has already been used -// - transaction: the transaction attempted -export const NONCE_EXPIRED = "NONCE_EXPIRED"; -// The replacement fee for the transaction is too low -// - transaction: the transaction attempted -export const REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED"; -// The gas limit could not be estimated -// - transaction: the transaction passed to estimateGas -export const UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT"; -//export const errors: { [ code: string ]: string } = { -//}; -/////////////////// -// Censorship -let _permanentCensorErrors = false; -let _censorErrors = false; -export function setCensorship(censorship, permanent) { - if (_permanentCensorErrors) { - throwError("error censorship permanent", UNSUPPORTED_OPERATION, { operation: "setCensorship" }); - } - _censorErrors = !!censorship; - _permanentCensorErrors = !!permanent; -} -/////////////////// -// Errors -export function makeError(message, code, params) { - if (_censorErrors) { - return new Error("unknown error"); - } - if (!code) { - code = UNKNOWN_ERROR; - } - if (!params) { - params = {}; - } - let messageDetails = []; - Object.keys(params).forEach((key) => { - try { - messageDetails.push(key + "=" + JSON.stringify(params[key])); - } - catch (error) { - messageDetails.push(key + "=" + JSON.stringify(params[key].toString())); - } - }); - messageDetails.push("version=" + version); - let reason = message; - if (messageDetails.length) { - message += " (" + messageDetails.join(", ") + ")"; - } - // @TODO: Any?? - let error = new Error(message); - error.reason = reason; - error.code = code; - Object.keys(params).forEach(function (key) { - error[key] = params[key]; - }); - return error; -} -// @TODO: Enum -export function throwError(message, code, params) { - throw makeError(message, code, params); -} -export function throwArgumentError(message, name, value) { - return throwError(message, INVALID_ARGUMENT, { - argument: name, - value: value - }); -} -/////////////////// -// Checking -export function checkArgumentCount(count, expectedCount, suffix) { - if (suffix) { - suffix = " " + suffix; - } - else { - suffix = ""; - } - if (count < expectedCount) { - throwError("missing argument" + suffix, MISSING_ARGUMENT, { count: count, expectedCount: expectedCount }); - } - if (count > expectedCount) { - throwError("too many arguments" + suffix, UNEXPECTED_ARGUMENT, { count: count, expectedCount: expectedCount }); - } -} -export function checkNew(target, kind) { - if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -/* -export function check(target: any: void { - if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -*/ -export function checkAbstract(target, kind) { - if (target === kind) { - throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", UNSUPPORTED_OPERATION, { name: target.name, operation: "new" }); - } - else if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -/* -export function checkTarget(target: any, kind: any): void { - if (target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -*/ -function _checkNormalize() { - try { - let missing = []; - // Make sure all forms of normalization are supported - ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => { - try { - "test".normalize(form); - } - catch (error) { - missing.push(form); - } - }); - if (missing.length) { - throw new Error("missing " + missing.join(", ")); - } - if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) { - throw new Error("broken implementation"); - } - } - catch (error) { - return error.message; - } - return null; -} -let _normalizeError = _checkNormalize(); -export function checkNormalize() { - if (_normalizeError) { - throwError("platform missing String.prototype.normalize", UNSUPPORTED_OPERATION, { - operation: "String.prototype.normalize", form: _normalizeError - }); - } -} -export function checkSafeUint53(value, message) { - if (typeof (value) !== "number") { - return; - } - if (message == null) { - message = "value not safe"; - } - if (value < 0 || value >= 0x1fffffffffffff) { - throwError(message, NUMERIC_FAULT, { - operation: "checkSafeInteger", - fault: "out-of-safe-range", - value: value - }); - } - if (value % 1) { - throwError(message, NUMERIC_FAULT, { - operation: "checkSafeInteger", - fault: "non-integer", - value: value - }); - } -} -/////////////////// -// Logging -const LogLevels = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 }; -let LogLevel = LogLevels["default"]; -export function setLogLevel(logLevel) { - let level = LogLevels[logLevel]; - if (level == null) { - warn("invalid log level - " + logLevel); - return; - } - LogLevel = level; -} -function log(logLevel, args) { - if (LogLevel > LogLevels[logLevel]) { - return; - } - console.log.apply(console, args); -} -export function warn(...args) { - log("warn", args); -} -export function info(...args) { - log("info", args); -} diff --git a/packages/errors/lib/_version.d.ts b/packages/errors/lib/_version.d.ts deleted file mode 100644 index 6fc5332c8..000000000 --- a/packages/errors/lib/_version.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare const version = "errors/5.0.1"; diff --git a/packages/errors/lib/_version.js b/packages/errors/lib/_version.js deleted file mode 100644 index 6beceb4aa..000000000 --- a/packages/errors/lib/_version.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.version = "errors/5.0.1"; diff --git a/packages/errors/lib/index.d.ts b/packages/errors/lib/index.d.ts deleted file mode 100644 index 1890f1255..000000000 --- a/packages/errors/lib/index.d.ts +++ /dev/null @@ -1,29 +0,0 @@ -export declare const UNKNOWN_ERROR = "UNKNOWN_ERROR"; -export declare const NOT_IMPLEMENTED = "NOT_IMPLEMENTED"; -export declare const UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION"; -export declare const NETWORK_ERROR = "NETWORK_ERROR"; -export declare const SERVER_ERROR = "SERVER_ERROR"; -export declare const TIMEOUT = "TIMEOUT"; -export declare const BUFFER_OVERRUN = "BUFFER_OVERRUN"; -export declare const NUMERIC_FAULT = "NUMERIC_FAULT"; -export declare const MISSING_NEW = "MISSING_NEW"; -export declare const INVALID_ARGUMENT = "INVALID_ARGUMENT"; -export declare const MISSING_ARGUMENT = "MISSING_ARGUMENT"; -export declare const UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT"; -export declare const CALL_EXCEPTION = "CALL_EXCEPTION"; -export declare const INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS"; -export declare const NONCE_EXPIRED = "NONCE_EXPIRED"; -export declare const REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED"; -export declare const UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT"; -export declare function setCensorship(censorship: boolean, permanent?: boolean): void; -export declare function makeError(message: string, code: string, params: any): Error; -export declare function throwError(message: string, code: string, params: any): never; -export declare function throwArgumentError(message: string, name: string, value: any): never; -export declare function checkArgumentCount(count: number, expectedCount: number, suffix?: string): void; -export declare function checkNew(target: any, kind: any): void; -export declare function checkAbstract(target: any, kind: any): void; -export declare function checkNormalize(): void; -export declare function checkSafeUint53(value: number, message?: string): void; -export declare function setLogLevel(logLevel: string): void; -export declare function warn(...args: Array): void; -export declare function info(...args: Array): void; diff --git a/packages/errors/lib/index.js b/packages/errors/lib/index.js deleted file mode 100644 index 101464ad5..000000000 --- a/packages/errors/lib/index.js +++ /dev/null @@ -1,266 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -//import { version } from "./_version"; -var version = "@TODO"; -/////////////////// -// Generic Errors -// Unknown Error -exports.UNKNOWN_ERROR = "UNKNOWN_ERROR"; -// Not Implemented -exports.NOT_IMPLEMENTED = "NOT_IMPLEMENTED"; -// Unsupported Operation -// - operation -exports.UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION"; -// Network Error (i.e. Ethereum Network, such as an invalid chain ID) -exports.NETWORK_ERROR = "NETWORK_ERROR"; -// Some sort of bad response from the server -exports.SERVER_ERROR = "SERVER_ERROR"; -// Timeout -exports.TIMEOUT = "TIMEOUT"; -/////////////////// -// Operational Errors -// Buffer Overrun -exports.BUFFER_OVERRUN = "BUFFER_OVERRUN"; -// Numeric Fault -// - operation: the operation being executed -// - fault: the reason this faulted -exports.NUMERIC_FAULT = "NUMERIC_FAULT"; -/////////////////// -// Argument Errors -// Missing new operator to an object -// - name: The name of the class -exports.MISSING_NEW = "MISSING_NEW"; -// Invalid argument (e.g. value is incompatible with type) to a function: -// - argument: The argument name that was invalid -// - value: The value of the argument -exports.INVALID_ARGUMENT = "INVALID_ARGUMENT"; -// Missing argument to a function: -// - count: The number of arguments received -// - expectedCount: The number of arguments expected -exports.MISSING_ARGUMENT = "MISSING_ARGUMENT"; -// Too many arguments -// - count: The number of arguments received -// - expectedCount: The number of arguments expected -exports.UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT"; -/////////////////// -// Blockchain Errors -// Call exception -// - transaction: the transaction -// - address?: the contract address -// - args?: The arguments passed into the function -// - method?: The Solidity method signature -// - errorSignature?: The EIP848 error signature -// - errorArgs?: The EIP848 error parameters -// - reason: The reason (only for EIP848 "Error(string)") -exports.CALL_EXCEPTION = "CALL_EXCEPTION"; -// Insufficien funds (< value + gasLimit * gasPrice) -// - transaction: the transaction attempted -exports.INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS"; -// Nonce has already been used -// - transaction: the transaction attempted -exports.NONCE_EXPIRED = "NONCE_EXPIRED"; -// The replacement fee for the transaction is too low -// - transaction: the transaction attempted -exports.REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED"; -// The gas limit could not be estimated -// - transaction: the transaction passed to estimateGas -exports.UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT"; -//export const errors: { [ code: string ]: string } = { -//}; -/////////////////// -// Censorship -var _permanentCensorErrors = false; -var _censorErrors = false; -function setCensorship(censorship, permanent) { - if (_permanentCensorErrors) { - throwError("error censorship permanent", exports.UNSUPPORTED_OPERATION, { operation: "setCensorship" }); - } - _censorErrors = !!censorship; - _permanentCensorErrors = !!permanent; -} -exports.setCensorship = setCensorship; -/////////////////// -// Errors -function makeError(message, code, params) { - if (_censorErrors) { - return new Error("unknown error"); - } - if (!code) { - code = exports.UNKNOWN_ERROR; - } - if (!params) { - params = {}; - } - var messageDetails = []; - Object.keys(params).forEach(function (key) { - try { - messageDetails.push(key + "=" + JSON.stringify(params[key])); - } - catch (error) { - messageDetails.push(key + "=" + JSON.stringify(params[key].toString())); - } - }); - messageDetails.push("version=" + version); - var reason = message; - if (messageDetails.length) { - message += " (" + messageDetails.join(", ") + ")"; - } - // @TODO: Any?? - var error = new Error(message); - error.reason = reason; - error.code = code; - Object.keys(params).forEach(function (key) { - error[key] = params[key]; - }); - return error; -} -exports.makeError = makeError; -// @TODO: Enum -function throwError(message, code, params) { - throw makeError(message, code, params); -} -exports.throwError = throwError; -function throwArgumentError(message, name, value) { - return throwError(message, exports.INVALID_ARGUMENT, { - argument: name, - value: value - }); -} -exports.throwArgumentError = throwArgumentError; -/////////////////// -// Checking -function checkArgumentCount(count, expectedCount, suffix) { - if (suffix) { - suffix = " " + suffix; - } - else { - suffix = ""; - } - if (count < expectedCount) { - throwError("missing argument" + suffix, exports.MISSING_ARGUMENT, { count: count, expectedCount: expectedCount }); - } - if (count > expectedCount) { - throwError("too many arguments" + suffix, exports.UNEXPECTED_ARGUMENT, { count: count, expectedCount: expectedCount }); - } -} -exports.checkArgumentCount = checkArgumentCount; -function checkNew(target, kind) { - if (target === Object || target == null) { - throwError("missing new", exports.MISSING_NEW, { name: kind.name }); - } -} -exports.checkNew = checkNew; -/* -export function check(target: any: void { - if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -*/ -function checkAbstract(target, kind) { - if (target === kind) { - throwError("cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", exports.UNSUPPORTED_OPERATION, { name: target.name, operation: "new" }); - } - else if (target === Object || target == null) { - throwError("missing new", exports.MISSING_NEW, { name: kind.name }); - } -} -exports.checkAbstract = checkAbstract; -/* -export function checkTarget(target: any, kind: any): void { - if (target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -*/ -function _checkNormalize() { - try { - var missing_1 = []; - // Make sure all forms of normalization are supported - ["NFD", "NFC", "NFKD", "NFKC"].forEach(function (form) { - try { - "test".normalize(form); - } - catch (error) { - missing_1.push(form); - } - }); - if (missing_1.length) { - throw new Error("missing " + missing_1.join(", ")); - } - if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) { - throw new Error("broken implementation"); - } - } - catch (error) { - return error.message; - } - return null; -} -var _normalizeError = _checkNormalize(); -function checkNormalize() { - if (_normalizeError) { - throwError("platform missing String.prototype.normalize", exports.UNSUPPORTED_OPERATION, { - operation: "String.prototype.normalize", form: _normalizeError - }); - } -} -exports.checkNormalize = checkNormalize; -function checkSafeUint53(value, message) { - if (typeof (value) !== "number") { - return; - } - if (message == null) { - message = "value not safe"; - } - if (value < 0 || value >= 0x1fffffffffffff) { - throwError(message, exports.NUMERIC_FAULT, { - operation: "checkSafeInteger", - fault: "out-of-safe-range", - value: value - }); - } - if (value % 1) { - throwError(message, exports.NUMERIC_FAULT, { - operation: "checkSafeInteger", - fault: "non-integer", - value: value - }); - } -} -exports.checkSafeUint53 = checkSafeUint53; -/////////////////// -// Logging -var LogLevels = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 }; -var LogLevel = LogLevels["default"]; -function setLogLevel(logLevel) { - var level = LogLevels[logLevel]; - if (level == null) { - warn("invalid log level - " + logLevel); - return; - } - LogLevel = level; -} -exports.setLogLevel = setLogLevel; -function log(logLevel, args) { - if (LogLevel > LogLevels[logLevel]) { - return; - } - console.log.apply(console, args); -} -function warn() { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - log("warn", args); -} -exports.warn = warn; -function info() { - var args = []; - for (var _i = 0; _i < arguments.length; _i++) { - args[_i] = arguments[_i]; - } - log("info", args); -} -exports.info = info; diff --git a/packages/errors/package.json b/packages/errors/package.json deleted file mode 100644 index 25e378526..000000000 --- a/packages/errors/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "author": "Richard Moore ", - "description": "Error utility functions for ethers.", - "ethereum": "donations.ethers.eth", - "keywords": [ - "Ethereum", - "ethers" - ], - "license": "MIT", - "main": "./lib/index.js", - "module": "./lib.esm/index.js", - "name": "@ethersproject/errors", - "publishConfig": { - "access": "public" - }, - "repository": { - "type": "git", - "url": "git://github.com/ethers-io/ethers.js.git" - }, - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, - "tarballHash": "0x2bc750f32fe5e42d9d3922ab3d73559662c9c120afe36a43b41e2a8a8e150004", - "types": "./lib/index.d.ts", - "version": "5.0.1" -} diff --git a/packages/errors/src.ts/_version.ts b/packages/errors/src.ts/_version.ts deleted file mode 100644 index 97dd69b28..000000000 --- a/packages/errors/src.ts/_version.ts +++ /dev/null @@ -1 +0,0 @@ -export const version = "errors/5.0.1"; diff --git a/packages/errors/src.ts/index.ts b/packages/errors/src.ts/index.ts deleted file mode 100644 index ff4c31e22..000000000 --- a/packages/errors/src.ts/index.ts +++ /dev/null @@ -1,344 +0,0 @@ -"use strict"; - -//import { version } from "./_version"; -const version = "@TODO"; - - -/////////////////// -// Generic Errors - -// Unknown Error -export const UNKNOWN_ERROR = "UNKNOWN_ERROR"; - -// Not Implemented -export const NOT_IMPLEMENTED = "NOT_IMPLEMENTED"; - -// Unsupported Operation -// - operation -export const UNSUPPORTED_OPERATION = "UNSUPPORTED_OPERATION"; - -// Network Error (i.e. Ethereum Network, such as an invalid chain ID) -export const NETWORK_ERROR = "NETWORK_ERROR"; - -// Some sort of bad response from the server -export const SERVER_ERROR = "SERVER_ERROR"; - -// Timeout -export const TIMEOUT = "TIMEOUT"; - -/////////////////// -// Operational Errors - -// Buffer Overrun -export const BUFFER_OVERRUN = "BUFFER_OVERRUN"; - -// Numeric Fault -// - operation: the operation being executed -// - fault: the reason this faulted -export const NUMERIC_FAULT = "NUMERIC_FAULT"; - - -/////////////////// -// Argument Errors - -// Missing new operator to an object -// - name: The name of the class -export const MISSING_NEW = "MISSING_NEW"; - -// Invalid argument (e.g. value is incompatible with type) to a function: -// - argument: The argument name that was invalid -// - value: The value of the argument -export const INVALID_ARGUMENT = "INVALID_ARGUMENT"; - -// Missing argument to a function: -// - count: The number of arguments received -// - expectedCount: The number of arguments expected -export const MISSING_ARGUMENT = "MISSING_ARGUMENT"; - -// Too many arguments -// - count: The number of arguments received -// - expectedCount: The number of arguments expected -export const UNEXPECTED_ARGUMENT = "UNEXPECTED_ARGUMENT"; - - -/////////////////// -// Blockchain Errors - -// Call exception -// - transaction: the transaction -// - address?: the contract address -// - args?: The arguments passed into the function -// - method?: The Solidity method signature -// - errorSignature?: The EIP848 error signature -// - errorArgs?: The EIP848 error parameters -// - reason: The reason (only for EIP848 "Error(string)") -export const CALL_EXCEPTION = "CALL_EXCEPTION"; - -// Insufficien funds (< value + gasLimit * gasPrice) -// - transaction: the transaction attempted -export const INSUFFICIENT_FUNDS = "INSUFFICIENT_FUNDS"; - -// Nonce has already been used -// - transaction: the transaction attempted -export const NONCE_EXPIRED = "NONCE_EXPIRED"; - -// The replacement fee for the transaction is too low -// - transaction: the transaction attempted -export const REPLACEMENT_UNDERPRICED = "REPLACEMENT_UNDERPRICED"; - -// The gas limit could not be estimated -// - transaction: the transaction passed to estimateGas -export const UNPREDICTABLE_GAS_LIMIT = "UNPREDICTABLE_GAS_LIMIT"; - -//export const errors: { [ code: string ]: string } = { -//}; - -/////////////////// -// Censorship - -let _permanentCensorErrors = false; -let _censorErrors = false; - -export function setCensorship(censorship: boolean, permanent?: boolean): void { - if (_permanentCensorErrors) { - throwError("error censorship permanent", UNSUPPORTED_OPERATION, { operation: "setCensorship" }); - } - - _censorErrors = !!censorship; - _permanentCensorErrors = !!permanent; -} - - -/////////////////// -// Errors - -export function makeError(message: string, code: string, params: any): Error { - if (_censorErrors) { - return new Error("unknown error"); - } - - if (!code) { code = UNKNOWN_ERROR; } - if (!params) { params = {}; } - - let messageDetails: Array = []; - Object.keys(params).forEach((key) => { - try { - messageDetails.push(key + "=" + JSON.stringify(params[key])); - } catch (error) { - messageDetails.push(key + "=" + JSON.stringify(params[key].toString())); - } - }); - messageDetails.push("version=" + version); - - let reason = message; - if (messageDetails.length) { - message += " (" + messageDetails.join(", ") + ")"; - } - - // @TODO: Any?? - let error: any = new Error(message); - error.reason = reason; - error.code = code - - Object.keys(params).forEach(function(key) { - error[key] = params[key]; - }); - - return error; -} - -// @TODO: Enum -export function throwError(message: string, code: string, params: any): never { - throw makeError(message, code, params); -} - - -export function throwArgumentError(message: string, name: string, value: any): never { - return throwError(message, INVALID_ARGUMENT, { - argument: name, - value: value - }); -} - - -/////////////////// -// Checking - -export function checkArgumentCount(count: number, expectedCount: number, suffix?: string): void { - if (suffix) { - suffix = " " + suffix; - } else { - suffix = ""; - } - - if (count < expectedCount) { - throwError("missing argument" + suffix, MISSING_ARGUMENT, { count: count, expectedCount: expectedCount }); - } - - if (count > expectedCount) { - throwError("too many arguments" + suffix, UNEXPECTED_ARGUMENT, { count: count, expectedCount: expectedCount }); - } -} - -export function checkNew(target: any, kind: any): void { - if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} - -/* -export function check(target: any: void { - if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -*/ - -export function checkAbstract(target: any, kind: any): void { - if (target === kind) { - throwError( - "cannot instantiate abstract class " + JSON.stringify(kind.name) + " directly; use a sub-class", - UNSUPPORTED_OPERATION, - { name: target.name, operation: "new" } - ); - } else if (target === Object || target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} - -/* -export function checkTarget(target: any, kind: any): void { - if (target == null) { - throwError("missing new", MISSING_NEW, { name: kind.name }); - } -} -*/ -function _checkNormalize(): string { - try { - let missing: Array = [ ]; - - // Make sure all forms of normalization are supported - ["NFD", "NFC", "NFKD", "NFKC"].forEach((form) => { - try { - "test".normalize(form); - } catch(error) { - missing.push(form); - } - }); - - if (missing.length) { - throw new Error("missing " + missing.join(", ")); - } - - if (String.fromCharCode(0xe9).normalize("NFD") !== String.fromCharCode(0x65, 0x0301)) { - throw new Error("broken implementation") - } - } catch (error) { - return error.message; - } - - return null; -} - -let _normalizeError = _checkNormalize(); -export function checkNormalize(): void { - if (_normalizeError) { - throwError("platform missing String.prototype.normalize", UNSUPPORTED_OPERATION, { - operation: "String.prototype.normalize", form: _normalizeError - }); - } -} - -export function checkSafeUint53(value: number, message?: string): void { - if (typeof(value) !== "number") { return; } - - if (message == null) { message = "value not safe"; } - - if (value < 0 || value >= 0x1fffffffffffff) { - throwError(message, NUMERIC_FAULT, { - operation: "checkSafeInteger", - fault: "out-of-safe-range", - value: value - }); - } - - if (value % 1) { - throwError(message, NUMERIC_FAULT, { - operation: "checkSafeInteger", - fault: "non-integer", - value: value - }); - } -} - - -/////////////////// -// Logging - -const LogLevels: { [ name: string ]: number } = { debug: 1, "default": 2, info: 2, warn: 3, error: 4, off: 5 }; -let LogLevel = LogLevels["default"]; - -export function setLogLevel(logLevel: string): void { - let level = LogLevels[logLevel]; - if (level == null) { - warn("invalid log level - " + logLevel); - return; - } - LogLevel = level; -} - -function log(logLevel: string, args: Array): void { - if (LogLevel > LogLevels[logLevel]) { return; } - console.log.apply(console, args); -} - -export function warn(...args: Array): void { - log("warn", args); -} - -export function info(...args: Array): void { - log("info", args); -} -/* -export class Logger { - readonly version: string; - _logLevel: number; - - constructor(version?: string) { - Object.defineProperty(this, "version", { - enumerable: true, - value: (version || "unknown"), - writable: false - }); - this._logLevel = LogLevels["default"];; - } - - _log(logLevel: string, args: Array): void { - if (this._logLevel > LogLevels[logLevel]) { return; } - console.log.apply(console, args); - } - - get logLevel(): number { - return this._logLevel; - } - - set logLevel(value: string | number) { - if (typeof(value) === "string") { - value = LogLevels[value]; - if (logLevel == null) { - this.warn("invliad log level - " + value); - return; - } - } - this._logLevel = value; - } - - warn(...args: Array): void { - this._log("warn", args); - } - - log(...args: Array): void { - this._log("info", args); - } -} -*/ diff --git a/packages/errors/tsconfig.json b/packages/errors/tsconfig.json deleted file mode 100644 index 324e49b1e..000000000 --- a/packages/errors/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.package.json", - "compilerOptions": { - "rootDir": "./src.ts", - "outDir": "./lib/" - }, - "include": [ - "./src.ts/*" - ], - "exclude": [] -} diff --git a/tsconfig.project.json b/tsconfig.project.json index a54472990..7a5d3bfb3 100644 --- a/tsconfig.project.json +++ b/tsconfig.project.json @@ -9,9 +9,6 @@ "pretty": false }, "references": [ - { - "path": "./packages/errors" - }, { "path": "./packages/logger" },