Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fuel-ts/errors

Package Overview
Dependencies
Maintainers
1
Versions
2511
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fuel-ts/errors - npm Package Compare versions

Comparing version 0.0.0-pr-1226-20230831171001 to 0.0.0-pr-1291-20230925153214

dist/test-utils/safeExec.d.ts

56

dist/error-codes.d.ts

@@ -5,11 +5,59 @@ /**

export declare enum ErrorCode {
ABI_TYPES_AND_VALUES_MISMATCH = "abi-types-and-values-mismatch",
ABI_MAIN_METHOD_MISSING = "abi-main-method-missing",
INVALID_COMPONENT = "invalid-component",
FRAGMENT_NOT_FOUND = "fragment-not-found",
CONFIGURABLE_NOT_FOUND = "configurable-not-found",
TYPE_NOT_FOUND = "type-not-found",
TYPE_NOT_SUPPORTED = "type-not-supported",
INVALID_DECODE_VALUE = "invalid-decode-value",
JSON_ABI_ERROR = "abi-main-method-missing",
TYPE_ID_NOT_FOUND = "type-id-not-found",
BIN_FILE_NOT_FOUND = "bin-file-not-found",
CODER_NOT_FOUND = "coder-not-found",
FUNCTION_NOT_FOUND = "function-not-found",
INVALID_BECH32_ADDRESS = "invalid-bech32-address",
INVALID_URL = "invalid-url",
/**
* The wallet doesn't have enough assets to cover the requirements of the transaction
*/
CHAIN_INFO_CACHE_EMPTY = "chain-info-cache-empty",
NODE_INFO_CACHE_EMPTY = "node-info-cache-empty",
INSUFFICIENT_BALANCE = "insufficient-balance",
WALLET_MANAGER_ERROR = "wallet-manager-error",
HD_WALLET_ERROR = "hd-wallet-error",
PARSE_FAILED = "parse-failed",
TRANSACTION_FAILED = "transaction-failed"
ENCODE_ERROR = "encode-error",
DECODE_ERROR = "decode-error",
INVALID_CREDENTIALS = "invalid-credentials",
ENV_DEPENDENCY_MISSING = "env-dependency-missing",
INVALID_TTL = "invalid-ttl",
INVALID_INPUT_PARAMETERS = "invalid-input-parameters",
NOT_IMPLEMENTED = "not-implemented",
NOT_SUPPORTED = "not-supported",
CONVERTING_FAILED = "converting-error",
ELEMENT_NOT_FOUND = "element-not-found",
MISSING_REQUIRED_PARAMETER = "missing-required-parameter",
GAS_PRICE_TOO_LOW = "gas-price-too-low",
GAS_LIMIT_TOO_LOW = "gas-limit-too-low",
TRANSACTION_NOT_FOUND = "transaction-not-found",
TRANSACTION_FAILED = "transaction-failed",
INVALID_CONFIGURABLE_CONSTANTS = "invalid-configurable-constants",
INVALID_TRANSACTION_INPUT = "invalid-transaction-input",
INVALID_TRANSACTION_OUTPUT = "invalid-transaction-output",
INVALID_TRANSACTION_STATUS = "invalid-transaction-status",
INVALID_TRANSACTION_TYPE = "invalid-transaction-type",
TRANSACTION_ERROR = "transaction-error",
INVALID_RECEIPT_TYPE = "invalid-receipt-type",
INVALID_WORD_LIST = "invalid-word-list",
INVALID_MNEMONIC = "invalid-mnemonic",
INVALID_ENTROPY = "invalid-entropy",
INVALID_SEED = "invalid-seed",
INVALID_CHECKSUM = "invalid-checksum",
INVALID_PASSWORD = "invalid-password",
ACCOUNT_REQUIRED = "account-required",
LATEST_BLOCK_UNAVAILABLE = "latest-block-unavailable",
ERROR_BUILDING_BLOCK_EXPLORER_URL = "error-building-block-explorer-url",
VITEPRESS_PLUGIN_ERROR = "vitepress-plugin-error",
INVALID_MULTICALL = "invalid-multicall",
SCRIPT_REVERTED = "script-reverted",
SCRIPT_RETURN_INVALID_TYPE = "script-return-invalid-type"
}
//# sourceMappingURL=error-codes.d.ts.map

@@ -12,7 +12,58 @@ "use strict";

var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
ErrorCode2["ABI_TYPES_AND_VALUES_MISMATCH"] = "abi-types-and-values-mismatch";
ErrorCode2["ABI_MAIN_METHOD_MISSING"] = "abi-main-method-missing";
ErrorCode2["INVALID_COMPONENT"] = "invalid-component";
ErrorCode2["FRAGMENT_NOT_FOUND"] = "fragment-not-found";
ErrorCode2["CONFIGURABLE_NOT_FOUND"] = "configurable-not-found";
ErrorCode2["TYPE_NOT_FOUND"] = "type-not-found";
ErrorCode2["TYPE_NOT_SUPPORTED"] = "type-not-supported";
ErrorCode2["INVALID_DECODE_VALUE"] = "invalid-decode-value";
ErrorCode2["JSON_ABI_ERROR"] = "abi-main-method-missing";
ErrorCode2["TYPE_ID_NOT_FOUND"] = "type-id-not-found";
ErrorCode2["BIN_FILE_NOT_FOUND"] = "bin-file-not-found";
ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
ErrorCode2["INVALID_URL"] = "invalid-url";
ErrorCode2["CHAIN_INFO_CACHE_EMPTY"] = "chain-info-cache-empty";
ErrorCode2["NODE_INFO_CACHE_EMPTY"] = "node-info-cache-empty";
ErrorCode2["INSUFFICIENT_BALANCE"] = "insufficient-balance";
ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
ErrorCode2["HD_WALLET_ERROR"] = "hd-wallet-error";
ErrorCode2["PARSE_FAILED"] = "parse-failed";
ErrorCode2["ENCODE_ERROR"] = "encode-error";
ErrorCode2["DECODE_ERROR"] = "decode-error";
ErrorCode2["INVALID_CREDENTIALS"] = "invalid-credentials";
ErrorCode2["ENV_DEPENDENCY_MISSING"] = "env-dependency-missing";
ErrorCode2["INVALID_TTL"] = "invalid-ttl";
ErrorCode2["INVALID_INPUT_PARAMETERS"] = "invalid-input-parameters";
ErrorCode2["NOT_IMPLEMENTED"] = "not-implemented";
ErrorCode2["NOT_SUPPORTED"] = "not-supported";
ErrorCode2["CONVERTING_FAILED"] = "converting-error";
ErrorCode2["ELEMENT_NOT_FOUND"] = "element-not-found";
ErrorCode2["MISSING_REQUIRED_PARAMETER"] = "missing-required-parameter";
ErrorCode2["GAS_PRICE_TOO_LOW"] = "gas-price-too-low";
ErrorCode2["GAS_LIMIT_TOO_LOW"] = "gas-limit-too-low";
ErrorCode2["TRANSACTION_NOT_FOUND"] = "transaction-not-found";
ErrorCode2["TRANSACTION_FAILED"] = "transaction-failed";
ErrorCode2["INVALID_CONFIGURABLE_CONSTANTS"] = "invalid-configurable-constants";
ErrorCode2["INVALID_TRANSACTION_INPUT"] = "invalid-transaction-input";
ErrorCode2["INVALID_TRANSACTION_OUTPUT"] = "invalid-transaction-output";
ErrorCode2["INVALID_TRANSACTION_STATUS"] = "invalid-transaction-status";
ErrorCode2["INVALID_TRANSACTION_TYPE"] = "invalid-transaction-type";
ErrorCode2["TRANSACTION_ERROR"] = "transaction-error";
ErrorCode2["INVALID_RECEIPT_TYPE"] = "invalid-receipt-type";
ErrorCode2["INVALID_WORD_LIST"] = "invalid-word-list";
ErrorCode2["INVALID_MNEMONIC"] = "invalid-mnemonic";
ErrorCode2["INVALID_ENTROPY"] = "invalid-entropy";
ErrorCode2["INVALID_SEED"] = "invalid-seed";
ErrorCode2["INVALID_CHECKSUM"] = "invalid-checksum";
ErrorCode2["INVALID_PASSWORD"] = "invalid-password";
ErrorCode2["ACCOUNT_REQUIRED"] = "account-required";
ErrorCode2["LATEST_BLOCK_UNAVAILABLE"] = "latest-block-unavailable";
ErrorCode2["ERROR_BUILDING_BLOCK_EXPLORER_URL"] = "error-building-block-explorer-url";
ErrorCode2["VITEPRESS_PLUGIN_ERROR"] = "vitepress-plugin-error";
ErrorCode2["INVALID_MULTICALL"] = "invalid-multicall";
ErrorCode2["SCRIPT_REVERTED"] = "script-reverted";
ErrorCode2["SCRIPT_RETURN_INVALID_TYPE"] = "script-return-invalid-type";
return ErrorCode2;

@@ -25,4 +76,4 @@ })(ErrorCode || {});

FORC: "0.44.0",
FUEL_CORE: "0.20.4",
FUELS: "0.54.0"
FUEL_CORE: "0.20.5",
FUELS: "0.59.0"
};

@@ -38,3 +89,6 @@ }

if (error.code === void 0) {
throw new _FuelError("parse-failed" /* PARSE_FAILED */, "missing 'code' property");
throw new _FuelError(
"parse-failed" /* PARSE_FAILED */,
"Failed to parse the error object. The required 'code' property is missing."
);
}

@@ -41,0 +95,0 @@ const enumValues = Object.values(ErrorCode);

@@ -35,7 +35,58 @@ "use strict";

var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
ErrorCode2["ABI_TYPES_AND_VALUES_MISMATCH"] = "abi-types-and-values-mismatch";
ErrorCode2["ABI_MAIN_METHOD_MISSING"] = "abi-main-method-missing";
ErrorCode2["INVALID_COMPONENT"] = "invalid-component";
ErrorCode2["FRAGMENT_NOT_FOUND"] = "fragment-not-found";
ErrorCode2["CONFIGURABLE_NOT_FOUND"] = "configurable-not-found";
ErrorCode2["TYPE_NOT_FOUND"] = "type-not-found";
ErrorCode2["TYPE_NOT_SUPPORTED"] = "type-not-supported";
ErrorCode2["INVALID_DECODE_VALUE"] = "invalid-decode-value";
ErrorCode2["JSON_ABI_ERROR"] = "abi-main-method-missing";
ErrorCode2["TYPE_ID_NOT_FOUND"] = "type-id-not-found";
ErrorCode2["BIN_FILE_NOT_FOUND"] = "bin-file-not-found";
ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
ErrorCode2["INVALID_URL"] = "invalid-url";
ErrorCode2["CHAIN_INFO_CACHE_EMPTY"] = "chain-info-cache-empty";
ErrorCode2["NODE_INFO_CACHE_EMPTY"] = "node-info-cache-empty";
ErrorCode2["INSUFFICIENT_BALANCE"] = "insufficient-balance";
ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
ErrorCode2["HD_WALLET_ERROR"] = "hd-wallet-error";
ErrorCode2["PARSE_FAILED"] = "parse-failed";
ErrorCode2["ENCODE_ERROR"] = "encode-error";
ErrorCode2["DECODE_ERROR"] = "decode-error";
ErrorCode2["INVALID_CREDENTIALS"] = "invalid-credentials";
ErrorCode2["ENV_DEPENDENCY_MISSING"] = "env-dependency-missing";
ErrorCode2["INVALID_TTL"] = "invalid-ttl";
ErrorCode2["INVALID_INPUT_PARAMETERS"] = "invalid-input-parameters";
ErrorCode2["NOT_IMPLEMENTED"] = "not-implemented";
ErrorCode2["NOT_SUPPORTED"] = "not-supported";
ErrorCode2["CONVERTING_FAILED"] = "converting-error";
ErrorCode2["ELEMENT_NOT_FOUND"] = "element-not-found";
ErrorCode2["MISSING_REQUIRED_PARAMETER"] = "missing-required-parameter";
ErrorCode2["GAS_PRICE_TOO_LOW"] = "gas-price-too-low";
ErrorCode2["GAS_LIMIT_TOO_LOW"] = "gas-limit-too-low";
ErrorCode2["TRANSACTION_NOT_FOUND"] = "transaction-not-found";
ErrorCode2["TRANSACTION_FAILED"] = "transaction-failed";
ErrorCode2["INVALID_CONFIGURABLE_CONSTANTS"] = "invalid-configurable-constants";
ErrorCode2["INVALID_TRANSACTION_INPUT"] = "invalid-transaction-input";
ErrorCode2["INVALID_TRANSACTION_OUTPUT"] = "invalid-transaction-output";
ErrorCode2["INVALID_TRANSACTION_STATUS"] = "invalid-transaction-status";
ErrorCode2["INVALID_TRANSACTION_TYPE"] = "invalid-transaction-type";
ErrorCode2["TRANSACTION_ERROR"] = "transaction-error";
ErrorCode2["INVALID_RECEIPT_TYPE"] = "invalid-receipt-type";
ErrorCode2["INVALID_WORD_LIST"] = "invalid-word-list";
ErrorCode2["INVALID_MNEMONIC"] = "invalid-mnemonic";
ErrorCode2["INVALID_ENTROPY"] = "invalid-entropy";
ErrorCode2["INVALID_SEED"] = "invalid-seed";
ErrorCode2["INVALID_CHECKSUM"] = "invalid-checksum";
ErrorCode2["INVALID_PASSWORD"] = "invalid-password";
ErrorCode2["ACCOUNT_REQUIRED"] = "account-required";
ErrorCode2["LATEST_BLOCK_UNAVAILABLE"] = "latest-block-unavailable";
ErrorCode2["ERROR_BUILDING_BLOCK_EXPLORER_URL"] = "error-building-block-explorer-url";
ErrorCode2["VITEPRESS_PLUGIN_ERROR"] = "vitepress-plugin-error";
ErrorCode2["INVALID_MULTICALL"] = "invalid-multicall";
ErrorCode2["SCRIPT_REVERTED"] = "script-reverted";
ErrorCode2["SCRIPT_RETURN_INVALID_TYPE"] = "script-return-invalid-type";
return ErrorCode2;

@@ -51,3 +102,6 @@ })(ErrorCode || {});

if (error.code === void 0) {
throw new _FuelError("parse-failed" /* PARSE_FAILED */, "missing 'code' property");
throw new _FuelError(
"parse-failed" /* PARSE_FAILED */,
"Failed to parse the error object. The required 'code' property is missing."
);
}

@@ -54,0 +108,0 @@ const enumValues = Object.values(ErrorCode);

@@ -0,2 +1,3 @@

export * from './test-utils/safeExec';
export * from './test-utils/expect-to-throw-fuel-error';
//# sourceMappingURL=test-utils.d.ts.map

129

dist/test-utils.global.js
"use strict";
(() => {
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw new Error('Dynamic require of "' + x + '" is not supported');
});
// src/test-utils/safeExec.ts
var safeExec = async (lambda) => {
let error;
let result;
try {
result = await lambda();
} catch (_error) {
error = _error;
}
return { error, result };
};
// src/test-utils/expect-to-throw-fuel-error.ts
var import_types = __require("util/types");
// src/error-codes.ts
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
ErrorCode2["ABI_TYPES_AND_VALUES_MISMATCH"] = "abi-types-and-values-mismatch";
ErrorCode2["ABI_MAIN_METHOD_MISSING"] = "abi-main-method-missing";
ErrorCode2["INVALID_COMPONENT"] = "invalid-component";
ErrorCode2["FRAGMENT_NOT_FOUND"] = "fragment-not-found";
ErrorCode2["CONFIGURABLE_NOT_FOUND"] = "configurable-not-found";
ErrorCode2["TYPE_NOT_FOUND"] = "type-not-found";
ErrorCode2["TYPE_NOT_SUPPORTED"] = "type-not-supported";
ErrorCode2["INVALID_DECODE_VALUE"] = "invalid-decode-value";
ErrorCode2["JSON_ABI_ERROR"] = "abi-main-method-missing";
ErrorCode2["TYPE_ID_NOT_FOUND"] = "type-id-not-found";
ErrorCode2["BIN_FILE_NOT_FOUND"] = "bin-file-not-found";
ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
ErrorCode2["INVALID_URL"] = "invalid-url";
ErrorCode2["CHAIN_INFO_CACHE_EMPTY"] = "chain-info-cache-empty";
ErrorCode2["NODE_INFO_CACHE_EMPTY"] = "node-info-cache-empty";
ErrorCode2["INSUFFICIENT_BALANCE"] = "insufficient-balance";
ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
ErrorCode2["HD_WALLET_ERROR"] = "hd-wallet-error";
ErrorCode2["PARSE_FAILED"] = "parse-failed";
ErrorCode2["ENCODE_ERROR"] = "encode-error";
ErrorCode2["DECODE_ERROR"] = "decode-error";
ErrorCode2["INVALID_CREDENTIALS"] = "invalid-credentials";
ErrorCode2["ENV_DEPENDENCY_MISSING"] = "env-dependency-missing";
ErrorCode2["INVALID_TTL"] = "invalid-ttl";
ErrorCode2["INVALID_INPUT_PARAMETERS"] = "invalid-input-parameters";
ErrorCode2["NOT_IMPLEMENTED"] = "not-implemented";
ErrorCode2["NOT_SUPPORTED"] = "not-supported";
ErrorCode2["CONVERTING_FAILED"] = "converting-error";
ErrorCode2["ELEMENT_NOT_FOUND"] = "element-not-found";
ErrorCode2["MISSING_REQUIRED_PARAMETER"] = "missing-required-parameter";
ErrorCode2["GAS_PRICE_TOO_LOW"] = "gas-price-too-low";
ErrorCode2["GAS_LIMIT_TOO_LOW"] = "gas-limit-too-low";
ErrorCode2["TRANSACTION_NOT_FOUND"] = "transaction-not-found";
ErrorCode2["TRANSACTION_FAILED"] = "transaction-failed";
ErrorCode2["INVALID_CONFIGURABLE_CONSTANTS"] = "invalid-configurable-constants";
ErrorCode2["INVALID_TRANSACTION_INPUT"] = "invalid-transaction-input";
ErrorCode2["INVALID_TRANSACTION_OUTPUT"] = "invalid-transaction-output";
ErrorCode2["INVALID_TRANSACTION_STATUS"] = "invalid-transaction-status";
ErrorCode2["INVALID_TRANSACTION_TYPE"] = "invalid-transaction-type";
ErrorCode2["TRANSACTION_ERROR"] = "transaction-error";
ErrorCode2["INVALID_RECEIPT_TYPE"] = "invalid-receipt-type";
ErrorCode2["INVALID_WORD_LIST"] = "invalid-word-list";
ErrorCode2["INVALID_MNEMONIC"] = "invalid-mnemonic";
ErrorCode2["INVALID_ENTROPY"] = "invalid-entropy";
ErrorCode2["INVALID_SEED"] = "invalid-seed";
ErrorCode2["INVALID_CHECKSUM"] = "invalid-checksum";
ErrorCode2["INVALID_PASSWORD"] = "invalid-password";
ErrorCode2["ACCOUNT_REQUIRED"] = "account-required";
ErrorCode2["LATEST_BLOCK_UNAVAILABLE"] = "latest-block-unavailable";
ErrorCode2["ERROR_BUILDING_BLOCK_EXPLORER_URL"] = "error-building-block-explorer-url";
ErrorCode2["VITEPRESS_PLUGIN_ERROR"] = "vitepress-plugin-error";
ErrorCode2["INVALID_MULTICALL"] = "invalid-multicall";
ErrorCode2["SCRIPT_REVERTED"] = "script-reverted";
ErrorCode2["SCRIPT_RETURN_INVALID_TYPE"] = "script-return-invalid-type";
return ErrorCode2;
})(ErrorCode || {});
// ../versions/dist/index.mjs
function getSupportedVersions() {
return {
FORC: "0.44.0",
FUEL_CORE: "0.20.4",
FUELS: "0.54.0"
};
}
var versions = getSupportedVersions();
// src/test-utils/expect-to-throw-fuel-error.ts
var errorCodes = Object.values(ErrorCode);
function assertExpectations(thrownError, expectedError) {
if (!errorCodes.includes(thrownError.code)) {
throw new Error("Thrown error code is not a valid FuelError code.");
var codes = Object.values(ErrorCode);
var expectToThrowFuelError = async (lambda, expectedError) => {
if (!expectedError.code) {
throw new Error("Expected error must contain a code.");
}
if (!errorCodes.includes(expectedError.code)) {
if (!codes.includes(expectedError.code)) {
throw new Error(`Expected error code '${expectedError.code}' is not a valid FuelError code.`);
}
expect(thrownError.name).toEqual("FuelError");
Object.getOwnPropertyNames(expectedError).filter((x) => x !== "stack").forEach((key) => {
expect(thrownError?.[key]).toStrictEqual(expectedError[key]);
});
}
function expectToThrowFuelError(lambda, expectedError) {
if ((0, import_types.isAsyncFunction)(lambda)) {
const promise = lambda();
return promise.then(
() => {
throw new Error("Passed-in lambda didn't throw.");
},
(e) => {
assertExpectations(e, expectedError);
}
const { error: thrownError } = await safeExec(lambda);
if (!thrownError) {
throw new Error(`Passed-in lambda didn't throw.`);
}
const thrownErrorStr = `Thrown error >>> ${thrownError.toString()}`;
if (!thrownError.code) {
throw new Error(`Thrown error must contain a code. ${thrownErrorStr}`);
}
if (!codes.includes(thrownError.code)) {
throw new Error(
`Thrown error code '${thrownError.code}' is not a valid FuelError code. ${thrownErrorStr}`
);
}
try {
lambda();
} catch (e) {
assertExpectations(e, expectedError);
return;
}
throw new Error("Passed-in lambda didn't throw.");
}
expect(thrownError.name).toEqual("FuelError");
expect(thrownError).toMatchObject(expectedError);
};
})();
//# sourceMappingURL=test-utils.global.js.map

@@ -23,60 +23,110 @@ "use strict";

__export(test_utils_exports, {
expectToThrowFuelError: () => expectToThrowFuelError
expectToThrowFuelError: () => expectToThrowFuelError,
safeExec: () => safeExec
});
module.exports = __toCommonJS(test_utils_exports);
// src/test-utils/expect-to-throw-fuel-error.ts
var import_types = require("util/types");
// src/test-utils/safeExec.ts
var safeExec = async (lambda) => {
let error;
let result;
try {
result = await lambda();
} catch (_error) {
error = _error;
}
return { error, result };
};
// src/error-codes.ts
var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
ErrorCode2["ABI_TYPES_AND_VALUES_MISMATCH"] = "abi-types-and-values-mismatch";
ErrorCode2["ABI_MAIN_METHOD_MISSING"] = "abi-main-method-missing";
ErrorCode2["INVALID_COMPONENT"] = "invalid-component";
ErrorCode2["FRAGMENT_NOT_FOUND"] = "fragment-not-found";
ErrorCode2["CONFIGURABLE_NOT_FOUND"] = "configurable-not-found";
ErrorCode2["TYPE_NOT_FOUND"] = "type-not-found";
ErrorCode2["TYPE_NOT_SUPPORTED"] = "type-not-supported";
ErrorCode2["INVALID_DECODE_VALUE"] = "invalid-decode-value";
ErrorCode2["JSON_ABI_ERROR"] = "abi-main-method-missing";
ErrorCode2["TYPE_ID_NOT_FOUND"] = "type-id-not-found";
ErrorCode2["BIN_FILE_NOT_FOUND"] = "bin-file-not-found";
ErrorCode2["CODER_NOT_FOUND"] = "coder-not-found";
ErrorCode2["FUNCTION_NOT_FOUND"] = "function-not-found";
ErrorCode2["INVALID_BECH32_ADDRESS"] = "invalid-bech32-address";
ErrorCode2["INVALID_URL"] = "invalid-url";
ErrorCode2["CHAIN_INFO_CACHE_EMPTY"] = "chain-info-cache-empty";
ErrorCode2["NODE_INFO_CACHE_EMPTY"] = "node-info-cache-empty";
ErrorCode2["INSUFFICIENT_BALANCE"] = "insufficient-balance";
ErrorCode2["WALLET_MANAGER_ERROR"] = "wallet-manager-error";
ErrorCode2["HD_WALLET_ERROR"] = "hd-wallet-error";
ErrorCode2["PARSE_FAILED"] = "parse-failed";
ErrorCode2["ENCODE_ERROR"] = "encode-error";
ErrorCode2["DECODE_ERROR"] = "decode-error";
ErrorCode2["INVALID_CREDENTIALS"] = "invalid-credentials";
ErrorCode2["ENV_DEPENDENCY_MISSING"] = "env-dependency-missing";
ErrorCode2["INVALID_TTL"] = "invalid-ttl";
ErrorCode2["INVALID_INPUT_PARAMETERS"] = "invalid-input-parameters";
ErrorCode2["NOT_IMPLEMENTED"] = "not-implemented";
ErrorCode2["NOT_SUPPORTED"] = "not-supported";
ErrorCode2["CONVERTING_FAILED"] = "converting-error";
ErrorCode2["ELEMENT_NOT_FOUND"] = "element-not-found";
ErrorCode2["MISSING_REQUIRED_PARAMETER"] = "missing-required-parameter";
ErrorCode2["GAS_PRICE_TOO_LOW"] = "gas-price-too-low";
ErrorCode2["GAS_LIMIT_TOO_LOW"] = "gas-limit-too-low";
ErrorCode2["TRANSACTION_NOT_FOUND"] = "transaction-not-found";
ErrorCode2["TRANSACTION_FAILED"] = "transaction-failed";
ErrorCode2["INVALID_CONFIGURABLE_CONSTANTS"] = "invalid-configurable-constants";
ErrorCode2["INVALID_TRANSACTION_INPUT"] = "invalid-transaction-input";
ErrorCode2["INVALID_TRANSACTION_OUTPUT"] = "invalid-transaction-output";
ErrorCode2["INVALID_TRANSACTION_STATUS"] = "invalid-transaction-status";
ErrorCode2["INVALID_TRANSACTION_TYPE"] = "invalid-transaction-type";
ErrorCode2["TRANSACTION_ERROR"] = "transaction-error";
ErrorCode2["INVALID_RECEIPT_TYPE"] = "invalid-receipt-type";
ErrorCode2["INVALID_WORD_LIST"] = "invalid-word-list";
ErrorCode2["INVALID_MNEMONIC"] = "invalid-mnemonic";
ErrorCode2["INVALID_ENTROPY"] = "invalid-entropy";
ErrorCode2["INVALID_SEED"] = "invalid-seed";
ErrorCode2["INVALID_CHECKSUM"] = "invalid-checksum";
ErrorCode2["INVALID_PASSWORD"] = "invalid-password";
ErrorCode2["ACCOUNT_REQUIRED"] = "account-required";
ErrorCode2["LATEST_BLOCK_UNAVAILABLE"] = "latest-block-unavailable";
ErrorCode2["ERROR_BUILDING_BLOCK_EXPLORER_URL"] = "error-building-block-explorer-url";
ErrorCode2["VITEPRESS_PLUGIN_ERROR"] = "vitepress-plugin-error";
ErrorCode2["INVALID_MULTICALL"] = "invalid-multicall";
ErrorCode2["SCRIPT_REVERTED"] = "script-reverted";
ErrorCode2["SCRIPT_RETURN_INVALID_TYPE"] = "script-return-invalid-type";
return ErrorCode2;
})(ErrorCode || {});
// src/fuel-error.ts
var import_versions = require("@fuel-ts/versions");
// src/test-utils/expect-to-throw-fuel-error.ts
var errorCodes = Object.values(ErrorCode);
function assertExpectations(thrownError, expectedError) {
if (!errorCodes.includes(thrownError.code)) {
throw new Error("Thrown error code is not a valid FuelError code.");
var codes = Object.values(ErrorCode);
var expectToThrowFuelError = async (lambda, expectedError) => {
if (!expectedError.code) {
throw new Error("Expected error must contain a code.");
}
if (!errorCodes.includes(expectedError.code)) {
if (!codes.includes(expectedError.code)) {
throw new Error(`Expected error code '${expectedError.code}' is not a valid FuelError code.`);
}
expect(thrownError.name).toEqual("FuelError");
Object.getOwnPropertyNames(expectedError).filter((x) => x !== "stack").forEach((key) => {
expect(thrownError?.[key]).toStrictEqual(expectedError[key]);
});
}
function expectToThrowFuelError(lambda, expectedError) {
if ((0, import_types.isAsyncFunction)(lambda)) {
const promise = lambda();
return promise.then(
() => {
throw new Error("Passed-in lambda didn't throw.");
},
(e) => {
assertExpectations(e, expectedError);
}
const { error: thrownError } = await safeExec(lambda);
if (!thrownError) {
throw new Error(`Passed-in lambda didn't throw.`);
}
const thrownErrorStr = `Thrown error >>> ${thrownError.toString()}`;
if (!thrownError.code) {
throw new Error(`Thrown error must contain a code. ${thrownErrorStr}`);
}
if (!codes.includes(thrownError.code)) {
throw new Error(
`Thrown error code '${thrownError.code}' is not a valid FuelError code. ${thrownErrorStr}`
);
}
try {
lambda();
} catch (e) {
assertExpectations(e, expectedError);
return;
}
throw new Error("Passed-in lambda didn't throw.");
}
expect(thrownError.name).toEqual("FuelError");
expect(thrownError).toMatchObject(expectedError);
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
expectToThrowFuelError
expectToThrowFuelError,
safeExec
});
//# sourceMappingURL=test-utils.js.map

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

import type { FuelError } from '../index';
declare function assertExpectations(thrownError: FuelError, expectedError: FuelError | (Partial<FuelError> & Required<Pick<FuelError, 'code'>>)): void;
export declare function expectToThrowFuelError<Fn extends () => unknown, R extends Promise<void> | void = ReturnType<Fn> extends Promise<unknown> ? Promise<void> : void>(lambda: Fn, expectedError: Parameters<typeof assertExpectations>[1]): R;
import type { FuelError } from '../fuel-error';
type ExpectedFuelError = Partial<FuelError> & Required<Pick<FuelError, 'code'>>;
export declare const expectToThrowFuelError: (lambda: () => unknown, expectedError: ExpectedFuelError) => Promise<void>;
export {};
//# sourceMappingURL=expect-to-throw-fuel-error.d.ts.map
{
"name": "@fuel-ts/errors",
"version": "0.0.0-pr-1226-20230831171001",
"version": "0.0.0-pr-1291-20230925153214",
"description": "Error class and error codes that the fuels-ts library throws",

@@ -33,4 +33,3 @@ "author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",

"dependencies": {
"@fuel-ts/utils": "0.0.0-pr-1226-20230831171001",
"@fuel-ts/versions": "0.0.0-pr-1226-20230831171001"
"@fuel-ts/versions": "0.0.0-pr-1291-20230925153214"
},

@@ -37,0 +36,0 @@ "scripts": {

@@ -13,3 +13,4 @@ # `@fuel-ts/errors`

- [Internal usage](#internal-usage)
- [Internal usage](#external-usage)
- [Test utilities](#test-utilities)
- [External usage](#external-usage)
- [Contributing](#contributing)

@@ -49,2 +50,28 @@ - [Changelog](#changelog)

### Test Utilities
You can use the `expectToThrowFuelError` test utility when asserting errors.
```ts
// can also be imported from `fuels` when using the umbrella package
import { expectToThrowFuelError } from "@fuel-ts/errors";
import { myFn } from "...";
describe('this and that' () => {
const code = FuelError.CODES.INVALID_URL;
it("should throw FuelError", async () => {
const expected = new FuelError(code);
await expectToThrowFuelError(() => myFn(), expected);
});
it("should throw something else", async () => {
const expected = new FuelError(code);
const fn = () => expectToThrowFuelError(() => myFn(), expected)
await expect(fn).rejects.toThrow('Something else');
});
})
```
### External usage

@@ -75,3 +102,3 @@

(function main() {
function main() {
try {

@@ -84,3 +111,3 @@ const p = new Provider("0004:tƨoʜlɒɔol//:qttʜ");

}
})();
);
```

@@ -87,0 +114,0 @@

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

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

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