@codama/errors
Version:
Error management for Codama
1 lines • 33 kB
Source Map (JSON)
{"version":3,"sources":["../src/cli/index.ts","../package.json","../src/context.ts","../src/codes.ts","../src/messages.ts","../src/message-formatter.ts"],"sourcesContent":["/**\n * Heavily inspired by @solana/errors.\n * @see https://github.com/anza-xyz/kit/blob/main/packages/errors\n */\n\nimport chalk from 'chalk';\nimport { Command, InvalidArgumentError } from 'commander';\n\nimport { version } from '../../package.json';\nimport { CodamaErrorCode } from '../codes';\nimport { decodeEncodedContext } from '../context';\nimport { getHumanReadableErrorMessage } from '../message-formatter';\nimport { CodamaErrorMessages } from '../messages';\n\nconst program = new Command();\n\nprogram.name('@codama/errors').description('Decode Codama JavaScript errors thrown in production').version(version);\n\nprogram\n .command('decode')\n .description('Decode a `CodamaErrorCode` to a human-readable message')\n .argument('<code>', 'numeric error code to decode', rawCode => {\n const code = parseInt(rawCode, 10);\n if (isNaN(code) || `${code}` !== rawCode) {\n throw new InvalidArgumentError('It must be an integer');\n }\n if (!(code in CodamaErrorMessages)) {\n throw new InvalidArgumentError('There exists no error with that code');\n }\n return code;\n })\n .argument('[encodedContext]', 'encoded context to interpolate into the error message', encodedContext => {\n try {\n return decodeEncodedContext(encodedContext);\n } catch {\n throw new InvalidArgumentError('Encoded context malformed');\n }\n })\n .action((code: number, context: object | undefined) => {\n const message = getHumanReadableErrorMessage(code as CodamaErrorCode, context);\n console.log(`\n${\n chalk.bold(\n chalk.rgb(154, 71, 255)('[') +\n chalk.rgb(144, 108, 244)('D') +\n chalk.rgb(134, 135, 233)('e') +\n chalk.rgb(122, 158, 221)('c') +\n chalk.rgb(110, 178, 209)('o') +\n chalk.rgb(95, 195, 196)('d') +\n chalk.rgb(79, 212, 181)('e') +\n chalk.rgb(57, 227, 166)('d') +\n chalk.rgb(19, 241, 149)(']'),\n ) + chalk.rgb(19, 241, 149)(' Codama error code #' + code)\n}\n - ${message}`);\n if (context) {\n console.log(`\n${chalk.yellowBright(chalk.bold('[Context]'))}\n ${JSON.stringify(context, null, 4).split('\\n').join('\\n ')}`);\n }\n });\n\nexport function run(argv: readonly string[]) {\n program.parse(argv);\n}\n","{\n \"name\": \"@codama/errors\",\n \"version\": \"1.3.1\",\n \"description\": \"Error management for Codama\",\n \"exports\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"react-native\": \"./dist/index.react-native.mjs\",\n \"browser\": {\n \"import\": \"./dist/index.browser.mjs\",\n \"require\": \"./dist/index.browser.cjs\"\n },\n \"node\": {\n \"import\": \"./dist/index.node.mjs\",\n \"require\": \"./dist/index.node.cjs\"\n }\n },\n \"browser\": {\n \"./dist/index.node.cjs\": \"./dist/index.browser.cjs\",\n \"./dist/index.node.mjs\": \"./dist/index.browser.mjs\"\n },\n \"main\": \"./dist/index.node.cjs\",\n \"module\": \"./dist/index.node.mjs\",\n \"react-native\": \"./dist/index.react-native.mjs\",\n \"types\": \"./dist/types/index.d.ts\",\n \"type\": \"commonjs\",\n \"bin\": \"./bin/cli.cjs\",\n \"files\": [\n \"./bin\",\n \"./dist/types\",\n \"./dist/cli.*\",\n \"./dist/index.*\"\n ],\n \"sideEffects\": false,\n \"keywords\": [\n \"solana\",\n \"framework\",\n \"standard\",\n \"specifications\"\n ],\n \"scripts\": {\n \"build\": \"rimraf dist && pnpm build:src && pnpm build:cli && pnpm build:types\",\n \"build:src\": \"zx ../../node_modules/@codama/internals/scripts/build-src.mjs package\",\n \"build:cli\": \"zx ../../node_modules/@codama/internals/scripts/build-src.mjs cli\",\n \"build:types\": \"zx ../../node_modules/@codama/internals/scripts/build-types.mjs\",\n \"dev\": \"zx ../../node_modules/@codama/internals/scripts/test-unit.mjs node --watch\",\n \"lint\": \"zx ../../node_modules/@codama/internals/scripts/lint.mjs\",\n \"lint:fix\": \"zx ../../node_modules/@codama/internals/scripts/lint.mjs --fix\",\n \"test\": \"pnpm test:types && pnpm test:treeshakability && pnpm test:browser && pnpm test:node && pnpm test:react-native\",\n \"test:browser\": \"zx ../../node_modules/@codama/internals/scripts/test-unit.mjs browser\",\n \"test:node\": \"zx ../../node_modules/@codama/internals/scripts/test-unit.mjs node\",\n \"test:react-native\": \"zx ../../node_modules/@codama/internals/scripts/test-unit.mjs react-native\",\n \"test:treeshakability\": \"zx ../../node_modules/@codama/internals/scripts/test-treeshakability.mjs\",\n \"test:types\": \"zx ../../node_modules/@codama/internals/scripts/test-types.mjs\"\n },\n \"dependencies\": {\n \"@codama/node-types\": \"workspace:*\",\n \"commander\": \"^14.0.0\",\n \"chalk\": \"^5.4.1\"\n },\n \"license\": \"MIT\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"https://github.com/codama-idl/codama\"\n },\n \"bugs\": {\n \"url\": \"http://github.com/codama-idl/codama/issues\"\n },\n \"browserslist\": [\n \"supports bigint and not dead\",\n \"maintained node versions\"\n ]\n}\n","/**\n * Heavily inspired by @solana/errors.\n * @see https://github.com/anza-xyz/kit/blob/main/packages/errors\n */\n\nimport {\n AccountNode,\n AccountValueNode,\n CamelCaseString,\n EnumTypeNode,\n InstructionAccountNode,\n InstructionArgumentNode,\n InstructionNode,\n LinkNode,\n Node,\n NodeKind,\n PdaNode,\n PdaSeedValueNode,\n ProgramNode,\n} from '@codama/node-types';\n\nimport {\n CODAMA_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING,\n CODAMA_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING,\n CODAMA_ERROR__ANCHOR__PROGRAM_ID_KIND_UNIMPLEMENTED,\n CODAMA_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED,\n CODAMA_ERROR__ANCHOR__TYPE_PATH_MISSING,\n CODAMA_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE,\n CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE,\n CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND,\n CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND,\n CODAMA_ERROR__LINKED_NODE_NOT_FOUND,\n CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE,\n CODAMA_ERROR__RENDERERS__UNSUPPORTED_NODE,\n CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND,\n CODAMA_ERROR__UNEXPECTED_NODE_KIND,\n CODAMA_ERROR__UNRECOGNIZED_BYTES_ENCODING,\n CODAMA_ERROR__UNRECOGNIZED_NODE_KIND,\n CODAMA_ERROR__UNRECOGNIZED_NUMBER_FORMAT,\n CODAMA_ERROR__VERSION_MISMATCH,\n CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND,\n CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES,\n CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION,\n CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES,\n CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK,\n CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE,\n CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES,\n CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE,\n CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND,\n CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY,\n CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER,\n CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES,\n CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND,\n CodamaErrorCode,\n} from './codes';\n\ntype DefaultUnspecifiedErrorContextToUndefined<T> = {\n [P in CodamaErrorCode]: P extends keyof T ? T[P] : undefined;\n};\n\n/**\n * WARNING:\n * - Don't change or remove members of an error's context.\n */\nexport type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{\n [CODAMA_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING]: {\n name: string;\n };\n [CODAMA_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING]: {\n name: string;\n };\n [CODAMA_ERROR__ANCHOR__PROGRAM_ID_KIND_UNIMPLEMENTED]: {\n kind: string;\n };\n [CODAMA_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED]: {\n kind: string;\n };\n [CODAMA_ERROR__ANCHOR__TYPE_PATH_MISSING]: {\n idlType: string;\n path: string;\n };\n [CODAMA_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE]: {\n idlType: string;\n };\n [CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE]: {\n field: CamelCaseString;\n };\n [CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND]: {\n field: CamelCaseString;\n };\n [CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND]: {\n enum: EnumTypeNode;\n enumName: CamelCaseString;\n variant: CamelCaseString;\n };\n [CODAMA_ERROR__LINKED_NODE_NOT_FOUND]: {\n kind: LinkNode['kind'];\n linkNode: LinkNode;\n name: CamelCaseString;\n path: readonly Node[];\n };\n [CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: {\n fsFunction: string;\n };\n [CODAMA_ERROR__RENDERERS__UNSUPPORTED_NODE]: {\n kind: NodeKind;\n node: Node | undefined;\n };\n [CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND]: {\n expectedKinds: NodeKind[];\n kind: NodeKind | null;\n node: Node | null | undefined;\n };\n [CODAMA_ERROR__UNEXPECTED_NODE_KIND]: {\n expectedKinds: NodeKind[];\n kind: NodeKind | null;\n node: Node | null | undefined;\n };\n [CODAMA_ERROR__UNRECOGNIZED_BYTES_ENCODING]: {\n encoding: string;\n };\n [CODAMA_ERROR__UNRECOGNIZED_NODE_KIND]: {\n kind: string;\n };\n [CODAMA_ERROR__UNRECOGNIZED_NUMBER_FORMAT]: {\n format: string;\n };\n [CODAMA_ERROR__VERSION_MISMATCH]: {\n codamaVersion: string;\n rootVersion: string;\n };\n [CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND]: {\n account: AccountNode;\n missingField: CamelCaseString;\n name: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES]: {\n duplicatedPdaNames: CamelCaseString[];\n program: ProgramNode;\n programName: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION]: {\n visitFunction: string;\n };\n [CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES]: {\n conflictingAttributes: CamelCaseString[];\n };\n [CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK]: {\n path: readonly Node[];\n };\n [CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE]: {\n instruction: InstructionNode;\n instructionAccount: InstructionAccountNode;\n instructionAccountName: CamelCaseString;\n instructionName: CamelCaseString;\n seed: PdaSeedValueNode<AccountValueNode>;\n seedName: CamelCaseString;\n seedValueName: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES]: {\n cycle: (InstructionAccountNode | InstructionArgumentNode)[];\n formattedCycle: string;\n instruction: InstructionNode;\n instructionName: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE]: {\n formattedHistogram: string;\n validationItems: ValidationItem[];\n };\n [CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]: {\n argumentName: CamelCaseString;\n instruction: InstructionNode;\n instructionName: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY]: {\n dependency: InstructionAccountNode | InstructionArgumentNode;\n dependencyKind: 'instructionAccountNode' | 'instructionArgumentNode';\n dependencyName: CamelCaseString;\n instruction: InstructionNode;\n instructionName: CamelCaseString;\n parent: InstructionAccountNode | InstructionArgumentNode;\n parentKind: 'instructionAccountNode' | 'instructionArgumentNode';\n parentName: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER]: {\n wrapper: string;\n };\n [CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES]: {\n instruction: InstructionNode;\n instructionName: CamelCaseString;\n pda: PdaNode;\n pdaName: CamelCaseString;\n };\n [CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND]: {\n key: string;\n };\n}>;\n\ntype ValidationItem = {\n level: 'debug' | 'error' | 'info' | 'trace' | 'warn';\n message: string;\n node: Node;\n path: Node[];\n};\n\nexport function decodeEncodedContext(encodedContext: string): object {\n const decodedUrlString = __NODEJS__ ? Buffer.from(encodedContext, 'base64').toString('utf8') : atob(encodedContext);\n return Object.fromEntries(new URLSearchParams(decodedUrlString).entries());\n}\n\nfunction encodeValue(value: unknown): string {\n if (Array.isArray(value)) {\n const commaSeparatedValues = value.map(encodeValue).join('%2C%20' /* \", \" */);\n return '%5B' /* \"[\" */ + commaSeparatedValues + /* \"]\" */ '%5D';\n } else if (typeof value === 'bigint') {\n return `${value}n`;\n } else {\n return encodeURIComponent(\n String(\n value != null && Object.getPrototypeOf(value) === null\n ? // Plain objects with no protoype don't have a `toString` method.\n // Convert them before stringifying them.\n { ...(value as object) }\n : value,\n ),\n );\n }\n}\n\nfunction encodeObjectContextEntry([key, value]: [string, unknown]): `${typeof key}=${string}` {\n return `${key}=${encodeValue(value)}`;\n}\n\nexport function encodeContextObject(context: object): string {\n const searchParamsString = Object.entries(context).map(encodeObjectContextEntry).join('&');\n return __NODEJS__ ? Buffer.from(searchParamsString, 'utf8').toString('base64') : btoa(searchParamsString);\n}\n","/**\n * Heavily inspired by @solana/errors.\n * @see https://github.com/anza-xyz/kit/blob/main/packages/errors\n *\n * ---\n *\n * WARNING:\n * - Don't remove error codes\n * - Don't change or reorder error codes.\n *\n * Good naming conventions:\n * - Prefixing common errors — e.g. under the same package — can be a good way to namespace them.\n * - Use consistent names — e.g. choose `PDA` or `PROGRAM_DERIVED_ADDRESS` and stick with it. Ensure your names are consistent with existing error codes. The decision might have been made for you.\n * - Recommended prefixes and suffixes:\n * - `MALFORMED_`: Some input was not constructed properly. E.g. `MALFORMED_BASE58_ENCODED_ADDRESS`.\n * - `INVALID_`: Some input is invalid (other than because it was MALFORMED). E.g. `INVALID_NUMBER_OF_BYTES`.\n * - `EXPECTED_`: Some input was different than expected, no need to specify the \"GOT\" part unless necessary. E.g. `EXPECTED_DECODED_ACCOUNT`.\n * - `_CANNOT_`: Some operation cannot be performed or some input cannot be used due to some condition. E.g. `CANNOT_DECODE_EMPTY_BYTE_ARRAY` or `PDA_CANNOT_END_WITH_PDA_MARKER`.\n * - `_MUST_BE_`: Some condition must be true. E.g. `NONCE_TRANSACTION_FIRST_INSTRUCTION_MUST_BE_ADVANCE_NONCE`.\n * - `_FAILED_TO_`: Tried to perform some operation and failed. E.g. `FAILED_TO_DECODE_ACCOUNT`.\n * - `_NOT_FOUND`: Some operation lead to not finding something. E.g. `ACCOUNT_NOT_FOUND`.\n * - `_OUT_OF_RANGE`: Some value is out of range. E.g. `ENUM_DISCRIMINATOR_OUT_OF_RANGE`.\n * - `_EXCEEDED`: Some limit was exceeded. E.g. `PDA_MAX_SEED_LENGTH_EXCEEDED`.\n * - `_MISMATCH`: Some elements do not match. E.g. `ENCODER_DECODER_FIXED_SIZE_MISMATCH`.\n * - `_MISSING`: Some required input is missing. E.g. `TRANSACTION_FEE_PAYER_MISSING`.\n * - `_UNIMPLEMENTED`: Some required component is not available in the environment. E.g. `SUBTLE_CRYPTO_VERIFY_FUNCTION_UNIMPLEMENTED`.\n */\nexport const CODAMA_ERROR__UNRECOGNIZED_NODE_KIND = 1;\nexport const CODAMA_ERROR__UNEXPECTED_NODE_KIND = 2;\nexport const CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND = 3;\nexport const CODAMA_ERROR__LINKED_NODE_NOT_FOUND = 4;\nexport const CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE = 5;\nexport const CODAMA_ERROR__VERSION_MISMATCH = 6;\nexport const CODAMA_ERROR__UNRECOGNIZED_NUMBER_FORMAT = 7;\nexport const CODAMA_ERROR__UNRECOGNIZED_BYTES_ENCODING = 8;\nexport const CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND = 9;\nexport const CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND = 10;\nexport const CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE = 11;\n\n// Visitors-related errors.\n// Reserve error codes in the range [1200000-1200999].\nexport const CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES = 1200000;\nexport const CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES = 1200001;\nexport const CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES = 1200002;\nexport const CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE = 1200003;\nexport const CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY = 1200004;\nexport const CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND = 1200005;\nexport const CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER = 1200006;\nexport const CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION = 1200007;\nexport const CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE = 1200008;\nexport const CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND = 1200009;\nexport const CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES = 1200010;\nexport const CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND = 1200011;\nexport const CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK = 1200012;\n\n// Anchor-related errors.\n// Reserve error codes in the range [2100000-2100999].\nexport const CODAMA_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE = 2100000;\nexport const CODAMA_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING = 2100001;\nexport const CODAMA_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING = 2100002;\nexport const CODAMA_ERROR__ANCHOR__TYPE_PATH_MISSING = 2100003;\nexport const CODAMA_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED = 2100004;\nexport const CODAMA_ERROR__ANCHOR__PROGRAM_ID_KIND_UNIMPLEMENTED = 2100005;\n\n// Renderers-related errors.\n// Reserve error codes in the range [2800000-2800999].\nexport const CODAMA_ERROR__RENDERERS__UNSUPPORTED_NODE = 2800000;\n\n/**\n * A union of every Codama error code\n *\n * You might be wondering why this is not a TypeScript enum or const enum.\n *\n * One of the goals of this library is to enable people to use some or none of it without having to\n * bundle all of it.\n *\n * If we made the set of error codes an enum then anyone who imported it (even if to only use a\n * single error code) would be forced to bundle every code and its label.\n *\n * Const enums appear to solve this problem by letting the compiler inline only the codes that are\n * actually used. Unfortunately exporting ambient (const) enums from a library like `@codama/errors`\n * is not safe, for a variety of reasons covered here: https://stackoverflow.com/a/28818850\n */\nexport type CodamaErrorCode =\n | typeof CODAMA_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING\n | typeof CODAMA_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING\n | typeof CODAMA_ERROR__ANCHOR__PROGRAM_ID_KIND_UNIMPLEMENTED\n | typeof CODAMA_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED\n | typeof CODAMA_ERROR__ANCHOR__TYPE_PATH_MISSING\n | typeof CODAMA_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE\n | typeof CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE\n | typeof CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND\n | typeof CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND\n | typeof CODAMA_ERROR__LINKED_NODE_NOT_FOUND\n | typeof CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE\n | typeof CODAMA_ERROR__RENDERERS__UNSUPPORTED_NODE\n | typeof CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND\n | typeof CODAMA_ERROR__UNEXPECTED_NODE_KIND\n | typeof CODAMA_ERROR__UNRECOGNIZED_BYTES_ENCODING\n | typeof CODAMA_ERROR__UNRECOGNIZED_NODE_KIND\n | typeof CODAMA_ERROR__UNRECOGNIZED_NUMBER_FORMAT\n | typeof CODAMA_ERROR__VERSION_MISMATCH\n | typeof CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND\n | typeof CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES\n | typeof CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION\n | typeof CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES\n | typeof CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK\n | typeof CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE\n | typeof CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES\n | typeof CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE\n | typeof CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND\n | typeof CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY\n | typeof CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER\n | typeof CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES\n | typeof CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND;\n","/**\n * Heavily inspired by @solana/errors.\n * @see https://github.com/anza-xyz/kit/blob/main/packages/errors\n */\n\nimport {\n CODAMA_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING,\n CODAMA_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING,\n CODAMA_ERROR__ANCHOR__PROGRAM_ID_KIND_UNIMPLEMENTED,\n CODAMA_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED,\n CODAMA_ERROR__ANCHOR__TYPE_PATH_MISSING,\n CODAMA_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE,\n CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE,\n CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND,\n CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND,\n CODAMA_ERROR__LINKED_NODE_NOT_FOUND,\n CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE,\n CODAMA_ERROR__RENDERERS__UNSUPPORTED_NODE,\n CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND,\n CODAMA_ERROR__UNEXPECTED_NODE_KIND,\n CODAMA_ERROR__UNRECOGNIZED_BYTES_ENCODING,\n CODAMA_ERROR__UNRECOGNIZED_NODE_KIND,\n CODAMA_ERROR__UNRECOGNIZED_NUMBER_FORMAT,\n CODAMA_ERROR__VERSION_MISMATCH,\n CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND,\n CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES,\n CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION,\n CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES,\n CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK,\n CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE,\n CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES,\n CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE,\n CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND,\n CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY,\n CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER,\n CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES,\n CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND,\n CodamaErrorCode,\n} from './codes';\n\n/**\n * WARNING:\n * - Don't change the meaning of an error message.\n */\nexport const CodamaErrorMessages: Readonly<{\n // This type makes this data structure exhaustive with respect to `SolanaErrorCode`.\n // TypeScript will fail to build this project if add an error code without a message.\n [P in CodamaErrorCode]: string;\n}> = {\n [CODAMA_ERROR__ANCHOR__ACCOUNT_TYPE_MISSING]: 'Account type [$name] is missing from the IDL types.',\n [CODAMA_ERROR__ANCHOR__ARGUMENT_TYPE_MISSING]: 'Argument name [$name] is missing from the instruction definition.',\n [CODAMA_ERROR__ANCHOR__PROGRAM_ID_KIND_UNIMPLEMENTED]: 'Program ID kind [$kind] is not implemented.',\n [CODAMA_ERROR__ANCHOR__SEED_KIND_UNIMPLEMENTED]: 'Seed kind [$kind] is not implemented.',\n [CODAMA_ERROR__ANCHOR__TYPE_PATH_MISSING]: 'Field type is missing for path [$path] in [$idlType].',\n [CODAMA_ERROR__ANCHOR__UNRECOGNIZED_IDL_TYPE]: 'Unrecognized Anchor IDL type [$idlType].',\n [CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE]: 'Discriminator field [$field] has no default value.',\n [CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND]: 'Could not find discriminator field [$field]',\n [CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND]: 'Enum variant [$variant] not found in enum type [$enumName].',\n [CODAMA_ERROR__LINKED_NODE_NOT_FOUND]: 'Could not find linked node [$name] from [$kind].',\n [CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]:\n 'Node.js filesystem function [$fsFunction] is not available in your environment.',\n [CODAMA_ERROR__RENDERERS__UNSUPPORTED_NODE]: 'Cannot render the encountered node of kind [$kind].',\n [CODAMA_ERROR__UNEXPECTED_NESTED_NODE_KIND]: 'Expected nested node of kind [$expectedKinds], got [$kind]',\n [CODAMA_ERROR__UNEXPECTED_NODE_KIND]: 'Expected node of kind [$expectedKinds], got [$kind].',\n [CODAMA_ERROR__UNRECOGNIZED_BYTES_ENCODING]: 'Unrecognized bytes encoding [$encoding].',\n [CODAMA_ERROR__UNRECOGNIZED_NODE_KIND]: 'Unrecognized node kind [$kind].',\n [CODAMA_ERROR__UNRECOGNIZED_NUMBER_FORMAT]: 'Unrecognized number format [$format].',\n [CODAMA_ERROR__VERSION_MISMATCH]:\n 'The provided RootNode version [$rootVersion] is not compatible with the installed Codama version [$codamaVersion].',\n [CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND]: 'Account [$name] does not have a field named [$missingField].',\n [CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES]:\n 'Cannot add PDAs to program [$programName] because the following PDA names already exist [$duplicatedPdaNames].',\n [CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION]:\n 'Cannot extend visitor with function [$visitFunction] as the base visitor does not support it.',\n [CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES]:\n 'Cannot flatten struct since this would cause the following attributes to conflict [$conflictingAttributes].',\n [CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK]: 'Cannot remove the last path in the node stack.',\n [CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE]:\n 'Cannot use optional account [$seedValueName] as the [$seedName] PDA seed for the [$instructionAccountName] account of the [$instructionName] instruction.',\n [CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES]:\n \"Circular dependency detected when resolving the accounts and arguments' default values of the [$instructionName] instruction. Got the following dependency cycle [$formattedCycle].\",\n [CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE]: 'Failed to validate the given node [$formattedHistogram].',\n [CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]:\n 'Could not find an enum argument named [$argumentName] for instruction [$instructionName].',\n [CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY]:\n 'Dependency [$dependencyName] of kind [$dependencyKind] is not a valid dependency of [$parentName] of kind [$parentKind] in the [$instructionName] instruction.',\n [CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER]: 'Invalid number wrapper kind [$wrapper].',\n [CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES]:\n 'Invalid seed values for PDA [$pdaName] in instruction [$instructionName].',\n [CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND]: 'Cannot find key [$key] in RenderMap.',\n};\n","/**\n * Heavily inspired by @solana/errors.\n * @see https://github.com/anza-xyz/kit/blob/main/packages/errors\n */\n\nimport { CodamaErrorCode } from './codes';\nimport { encodeContextObject } from './context';\nimport { CodamaErrorMessages } from './messages';\n\nexport function getHumanReadableErrorMessage<TErrorCode extends CodamaErrorCode>(\n code: TErrorCode,\n context: object = {},\n): string {\n const messageFormatString = CodamaErrorMessages[code];\n const message = messageFormatString.replace(/(?<!\\\\)\\$(\\w+)/g, (substring, variableName) =>\n variableName in context ? `${context[variableName as keyof typeof context] as string}` : substring,\n );\n return message;\n}\n\nexport function getErrorMessage<TErrorCode extends CodamaErrorCode>(code: TErrorCode, context: object = {}): string {\n if (process.env.NODE_ENV !== 'production') {\n return getHumanReadableErrorMessage(code, context);\n } else {\n let decodingAdviceMessage = `Codama error #${code}; Decode this error by running \\`npx @codama/errors decode -- ${code}`;\n if (Object.keys(context).length) {\n /**\n * DANGER: Be sure that the shell command is escaped in such a way that makes it\n * impossible for someone to craft malicious context values that would result in\n * an exploit against anyone who bindly copy/pastes it into their terminal.\n */\n decodingAdviceMessage += ` '${encodeContextObject(context)}'`;\n }\n return `${decodingAdviceMessage}\\``;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,mBAAkB;AAClB,uBAA8C;;;ACJ1C,cAAW;;;AC2MR,SAAS,qBAAqB,gBAAgC;AACjE,QAAM,mBAAmB,OAAa,OAAO,KAAK,gBAAgB,QAAQ,EAAE,SAAS,MAAM,IAAI,KAAK,cAAc;AAClH,SAAO,OAAO,YAAY,IAAI,gBAAgB,gBAAgB,EAAE,QAAQ,CAAC;AAC7E;;;ACrLO,IAAM,uCAAuC;AAC7C,IAAM,qCAAqC;AAC3C,IAAM,4CAA4C;AAClD,IAAM,sCAAsC;AAC5C,IAAM,qDAAqD;AAC3D,IAAM,iCAAiC;AACvC,IAAM,2CAA2C;AACjD,IAAM,4CAA4C;AAClD,IAAM,uCAAuC;AAC7C,IAAM,8CAA8C;AACpD,IAAM,yDAAyD;AAI/D,IAAM,0DAA0D;AAChE,IAAM,kDAAkD;AACxD,IAAM,+FAA+F;AACrG,IAAM,wEAAwE;AAC9E,IAAM,uEAAuE;AAC7E,IAAM,kDAAkD;AACxD,I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