Skip to content

AIDK API Reference / aidk-shared / ValidationError

Class: ValidationError ​

Defined in: packages/shared/src/errors.ts:302

Error thrown when input validation fails.

Example ​

typescript
throw new ValidationError('messages', 'Messages are required');
throw new ValidationError('handler', 'Handler function required', { expected: 'function' });
throw new ValidationError('input.model', 'Model identifier must be provided');

Extends ​

Constructors ​

Constructor ​

ts
new ValidationError(
   field: string, 
   message: string, 
   options: {
  code?:   | "VALIDATION_REQUIRED"
     | "VALIDATION_TYPE"
     | "VALIDATION_FORMAT"
     | "VALIDATION_CONSTRAINT";
  expected?: string;
  received?: string;
}, 
   cause?: Error): ValidationError;

Defined in: packages/shared/src/errors.ts:312

Parameters ​

ParameterType
fieldstring
messagestring
options{ code?: | "VALIDATION_REQUIRED" | "VALIDATION_TYPE" | "VALIDATION_FORMAT" | "VALIDATION_CONSTRAINT"; expected?: string; received?: string; }
options.code?| "VALIDATION_REQUIRED" | "VALIDATION_TYPE" | "VALIDATION_FORMAT" | "VALIDATION_CONSTRAINT"
options.expected?string
options.received?string
cause?Error

Returns ​

ValidationError

Overrides ​

AIDKError.constructor

Properties ​

PropertyModifierTypeDescriptionInherited fromDefined in
codereadonlyAIDKErrorCodeUnique error code for programmatic handlingAIDKError.codepackages/shared/src/errors.ts:100
detailsreadonlyRecord<string, unknown>Additional error detailsAIDKError.detailspackages/shared/src/errors.ts:103
expected?readonlystringExpected type or format (optional)-packages/shared/src/errors.ts:307
fieldreadonlystringField or parameter that failed validation-packages/shared/src/errors.ts:304
received?readonlystringActual value received (optional)-packages/shared/src/errors.ts:310

Methods ​

fromJSON() ​

ts
static fromJSON(json: SerializedAIDKError): AIDKError;

Defined in: packages/shared/src/errors.ts:163

Create error from serialized format

Parameters ​

ParameterType
jsonSerializedAIDKError

Returns ​

AIDKError

Inherited from ​

AIDKError.fromJSON


required() ​

ts
static required(field: string, message?: string): ValidationError;

Defined in: packages/shared/src/errors.ts:347

Create a "required" validation error

Parameters ​

ParameterType
fieldstring
message?string

Returns ​

ValidationError


toJSON() ​

ts
toJSON(): SerializedAIDKError;

Defined in: packages/shared/src/errors.ts:131

Serialize error for transport (JSON-safe)

Returns ​

SerializedAIDKError

Inherited from ​

AIDKError.toJSON


type() ​

ts
static type(
   field: string, 
   expected: string, 
   received?: string): ValidationError;

Defined in: packages/shared/src/errors.ts:356

Create a "type mismatch" validation error

Parameters ​

ParameterType
fieldstring
expectedstring
received?string

Returns ​

ValidationError

Released under the MIT License.