Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 50 additions & 49 deletions packages/errors/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -162,20 +163,20 @@ 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;
};
[CODAMA_ERROR__DYNAMIC_CLIENT__INVARIANT_VIOLATION]: {
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;
Expand All @@ -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;
Expand All @@ -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]: {
Expand Down Expand Up @@ -254,65 +255,65 @@ 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[];
};
[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<AccountValueNode>;
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)[];
Comment thread
lorisleiva marked this conversation as resolved.
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;
Expand Down
2 changes: 1 addition & 1 deletion packages/errors/src/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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].',
Expand Down
4 changes: 2 additions & 2 deletions packages/errors/test/error.typetest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
Expand All @@ -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, {
Expand Down