From 34df2cc427679bf373045ed05ee82dd3e8ee2f8b Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Mon, 21 Sep 2026 11:42:38 +0100 Subject: [PATCH] Adapt errors to Codama v2 --- packages/errors/src/context.ts | 99 +++++++++++++------------- packages/errors/src/messages.ts | 2 +- packages/errors/test/error.typetest.ts | 4 +- 3 files changed, 53 insertions(+), 52 deletions(-) diff --git a/packages/errors/src/context.ts b/packages/errors/src/context.ts index 4d29a551c..811de3145 100644 --- a/packages/errors/src/context.ts +++ b/packages/errors/src/context.ts @@ -6,18 +6,19 @@ import { AccountNode, AccountValueNode, - ArgumentValueNode, - CamelCaseString, + DataValueNode, EnumTypeNode, + IdentifierString, InstructionAccountNode, - InstructionArgumentNode, InstructionNode, LinkNode, Node, NodeKind, + PathString, PdaNode, PdaSeedValueNode, ProgramNode, + StructFieldTypeNode, } from '@codama/node-types'; import { @@ -115,22 +116,22 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ idlType: string; }; [CODAMA_ERROR__DISCRIMINATOR_FIELD_HAS_NO_DEFAULT_VALUE]: { - field: CamelCaseString; + field: IdentifierString; }; [CODAMA_ERROR__DISCRIMINATOR_FIELD_NOT_FOUND]: { - field: CamelCaseString; + field: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__ACCOUNT_MISSING]: { - accountName: CamelCaseString; - instructionName: CamelCaseString; + accountName: IdentifierString; + instructionName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__ACCOUNT_RESOLVER_MISSING]: { - accountName: CamelCaseString; - resolverName: CamelCaseString; + accountName: IdentifierString; + resolverName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__ARGUMENT_MISSING]: { - argumentName: CamelCaseString; - instructionName: CamelCaseString; + argumentName: IdentifierString; + instructionName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__CANNOT_CONVERT_TO_ADDRESS]: { value: string; @@ -139,20 +140,20 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ chain: string; }; [CODAMA_ERROR__DYNAMIC_CLIENT__DEFAULT_VALUE_MISSING]: { - argumentName: CamelCaseString; - instructionName: CamelCaseString; + argumentName: IdentifierString; + instructionName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__FAILED_TO_DERIVE_PDA]: { - accountName: CamelCaseString; + accountName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__FAILED_TO_ENCODE_ARGUMENT]: { - argumentName: CamelCaseString; - instructionName: CamelCaseString; + argumentName: IdentifierString; + instructionName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__FAILED_TO_EXECUTE_RESOLVER]: { - resolverName: CamelCaseString; + resolverName: IdentifierString; targetKind: NodeKind; - targetName: CamelCaseString; + targetName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__FAILED_TO_VALIDATE_INPUT]: { message: string; @@ -162,11 +163,11 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ instructionName: string; }; [CODAMA_ERROR__DYNAMIC_CLIENT__INVALID_ACCOUNT_ADDRESS]: { - accountName: CamelCaseString; + accountName: IdentifierString; value: string; }; [CODAMA_ERROR__DYNAMIC_CLIENT__INVALID_ARGUMENT_INPUT]: { - argumentName: CamelCaseString; + argumentName: IdentifierString; expectedType: string; value: string; }; @@ -174,8 +175,8 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ message: string; }; [CODAMA_ERROR__DYNAMIC_CLIENT__NODE_REFERENCE_NOT_FOUND]: { - instructionName: CamelCaseString; - referencedName: CamelCaseString; + instructionName: IdentifierString; + referencedName: IdentifierString; }; [CODAMA_ERROR__DYNAMIC_CLIENT__PDA_NOT_FOUND]: { available: string; @@ -196,14 +197,14 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ nodeKind: NodeKind; }; [CODAMA_ERROR__DYNAMIC_CLIENT__UNSUPPORTED_OPTIONAL_ACCOUNT_STRATEGY]: { - accountName: CamelCaseString; - instructionName: CamelCaseString; + accountName: IdentifierString; + instructionName: IdentifierString; strategy: string; }; [CODAMA_ERROR__ENUM_VARIANT_NOT_FOUND]: { enum: EnumTypeNode; - enumName: CamelCaseString; - variant: CamelCaseString; + enumName: IdentifierString; + variant: IdentifierString; }; [CODAMA_ERROR__INVALID_BRANDED_STRING]: { actual: string; @@ -212,7 +213,7 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ [CODAMA_ERROR__LINKED_NODE_NOT_FOUND]: { kind: LinkNode['kind']; linkNode: LinkNode; - name: CamelCaseString; + name: IdentifierString; path: readonly Node[]; }; [CODAMA_ERROR__NODE_FILESYSTEM_FUNCTION_UNAVAILABLE]: { @@ -254,19 +255,19 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ }; [CODAMA_ERROR__VISITORS__ACCOUNT_FIELD_NOT_FOUND]: { account: AccountNode; - missingField: CamelCaseString; - name: CamelCaseString; + missingField: IdentifierString; + name: IdentifierString; }; [CODAMA_ERROR__VISITORS__CANNOT_ADD_DUPLICATED_PDA_NAMES]: { - duplicatedPdaNames: CamelCaseString[]; + duplicatedPdaNames: IdentifierString[]; program: ProgramNode; - programName: CamelCaseString; + programName: IdentifierString; }; [CODAMA_ERROR__VISITORS__CANNOT_EXTEND_MISSING_VISIT_FUNCTION]: { visitFunction: string; }; [CODAMA_ERROR__VISITORS__CANNOT_FLATTEN_STRUCT_WITH_CONFLICTING_ATTRIBUTES]: { - conflictingAttributes: CamelCaseString[]; + conflictingAttributes: IdentifierString[]; }; [CODAMA_ERROR__VISITORS__CANNOT_REMOVE_LAST_PATH_IN_NODE_STACK]: { path: readonly Node[]; @@ -274,45 +275,45 @@ export type CodamaErrorContext = DefaultUnspecifiedErrorContextToUndefined<{ [CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE]: { instruction: InstructionNode; instructionAccount: InstructionAccountNode; - instructionAccountName: CamelCaseString; - instructionName: CamelCaseString; + instructionAccountName: IdentifierString; + instructionName: IdentifierString; seed: PdaSeedValueNode; - seedName: CamelCaseString; - seedValueName: CamelCaseString; + seedName: IdentifierString; + seedValueName: IdentifierString; }; [CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES]: { - cycle: (InstructionAccountNode | InstructionArgumentNode)[]; + cycle: (InstructionAccountNode | StructFieldTypeNode)[]; formattedCycle: string; instruction: InstructionNode; - instructionName: CamelCaseString; + instructionName: IdentifierString; }; [CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE]: { formattedHistogram: string; validationItems: readonly ValidationItem[]; }; [CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]: { - argumentName: CamelCaseString; + argumentName: IdentifierString; instruction: InstructionNode; - instructionName: CamelCaseString; + instructionName: IdentifierString; }; [CODAMA_ERROR__VISITORS__INVALID_INSTRUCTION_DEFAULT_VALUE_DEPENDENCY]: { - dependency: AccountValueNode | ArgumentValueNode; - dependencyKind: 'accountValueNode' | 'argumentValueNode'; - dependencyName: CamelCaseString; + dependency: AccountValueNode | DataValueNode; + dependencyKind: 'accountValueNode' | 'dataValueNode'; + dependencyName: IdentifierString | PathString; instruction: InstructionNode; - instructionName: CamelCaseString; - parent: InstructionAccountNode | InstructionArgumentNode; - parentKind: 'instructionAccountNode' | 'instructionArgumentNode'; - parentName: CamelCaseString; + instructionName: IdentifierString; + parent: InstructionAccountNode | StructFieldTypeNode; + parentKind: 'instructionAccountNode' | 'structFieldTypeNode'; + parentName: IdentifierString | PathString; }; [CODAMA_ERROR__VISITORS__INVALID_NUMBER_WRAPPER]: { wrapper: string; }; [CODAMA_ERROR__VISITORS__INVALID_PDA_SEED_VALUES]: { instruction: InstructionNode; - instructionName: CamelCaseString; + instructionName: IdentifierString; pda: PdaNode; - pdaName: CamelCaseString; + pdaName: IdentifierString; }; [CODAMA_ERROR__VISITORS__RENDER_MAP_KEY_NOT_FOUND]: { key: string; diff --git a/packages/errors/src/messages.ts b/packages/errors/src/messages.ts index b5fbefdc3..db56cccc9 100644 --- a/packages/errors/src/messages.ts +++ b/packages/errors/src/messages.ts @@ -142,7 +142,7 @@ export const CodamaErrorMessages: Readonly<{ [CODAMA_ERROR__VISITORS__CANNOT_USE_OPTIONAL_ACCOUNT_AS_PDA_SEED_VALUE]: 'Cannot use optional account [$seedValueName] as the [$seedName] PDA seed for the [$instructionAccountName] account of the [$instructionName] instruction.', [CODAMA_ERROR__VISITORS__CYCLIC_DEPENDENCY_DETECTED_WHEN_RESOLVING_INSTRUCTION_DEFAULT_VALUES]: - "Circular dependency detected when resolving the accounts and arguments' default values of the [$instructionName] instruction. Got the following dependency cycle [$formattedCycle].", + 'Circular dependency detected when resolving the default values of the [$instructionName] instruction. Got the following dependency cycle [$formattedCycle].', [CODAMA_ERROR__VISITORS__FAILED_TO_VALIDATE_NODE]: 'Failed to validate the given node [$formattedHistogram].', [CODAMA_ERROR__VISITORS__INSTRUCTION_ENUM_ARGUMENT_NOT_FOUND]: 'Could not find an enum argument named [$argumentName] for instruction [$instructionName].', diff --git a/packages/errors/test/error.typetest.ts b/packages/errors/test/error.typetest.ts index d710f07cc..eca9e35fa 100644 --- a/packages/errors/test/error.typetest.ts +++ b/packages/errors/test/error.typetest.ts @@ -11,7 +11,7 @@ const { CODAMA_ERROR__UNRECOGNIZED_NODE_KIND, CODAMA_ERROR__UNEXPECTED_NODE_KIND Object.values(CodamaErrorCodeModule) satisfies CodamaErrorCode[]; const unexpectedNodeKindError = new CodamaError(CODAMA_ERROR__UNEXPECTED_NODE_KIND, { - expectedKinds: ['numberTypeNode', 'stringTypeNode'], + expectedKinds: ['integerTypeNode', 'stringTypeNode'], kind: 'publicKeyTypeNode', node: {} as PublicKeyTypeNode, }); @@ -28,7 +28,7 @@ const unexpectedNodeKindError = new CodamaError(CODAMA_ERROR__UNEXPECTED_NODE_KI new CodamaError(CODAMA_ERROR__UNEXPECTED_NODE_KIND, {}); // @ts-expect-error Missing part of the context. new CodamaError(CODAMA_ERROR__UNEXPECTED_NODE_KIND, { - expectedKinds: ['numberTypeNode', 'stringTypeNode'], + expectedKinds: ['integerTypeNode', 'stringTypeNode'], node: {} as PublicKeyTypeNode, }); new CodamaError(CODAMA_ERROR__UNEXPECTED_NODE_KIND, {