Skip to content
IC Reactor

ValidationError

Defined in: core/src/errors/index.ts:393

Error thrown when argument validation fails before calling the canister. Contains detailed information about which fields failed validation.

try {
await reactor.callMethod({
functionName: "transfer",
args: [{ to: "", amount: -100 }],
})
} catch (error) {
if (isValidationError(error)) {
console.log(error.issues)
// [
// { path: ["to"], message: "Recipient is required" },
// { path: ["amount"], message: "Amount must be positive" }
// ]
}
}
  • Error

new ValidationError(methodName, issues): ValidationError

Defined in: core/src/errors/index.ts:399

string

ValidationIssue[]

ValidationError

Error.constructor

readonly issues: ValidationIssue[]

Defined in: core/src/errors/index.ts:395

Array of validation issues


readonly methodName: string

Defined in: core/src/errors/index.ts:397

The method name that failed validation

toJSON(): unknown

Defined in: core/src/errors/index.ts:413

JSON form, with any BigInt in the issues written as a string.

unknown


getIssuesForPath(path): ValidationIssue[]

Defined in: core/src/errors/index.ts:423

Get the issues whose path contains the given segment: a field name, or an array index. zod reports an index as a number, and 1 and "1" both match it. Pass "" for issues about the whole argument (an empty path), the key React’s mapValidationErrors files them under.

string | number

ValidationIssue[]


hasErrorForPath(path): boolean

Defined in: core/src/errors/index.ts:431

Check whether any issue’s path contains the given segment, matched the same way as getIssuesForPath, "" included.

string | number

boolean