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 ​
| Parameter | Type |
|---|---|
field | string |
message | string |
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 ​
Properties ​
| Property | Modifier | Type | Description | Inherited from | Defined in |
|---|---|---|---|---|---|
code | readonly | AIDKErrorCode | Unique error code for programmatic handling | AIDKError.code | packages/shared/src/errors.ts:100 |
details | readonly | Record<string, unknown> | Additional error details | AIDKError.details | packages/shared/src/errors.ts:103 |
expected? | readonly | string | Expected type or format (optional) | - | packages/shared/src/errors.ts:307 |
field | readonly | string | Field or parameter that failed validation | - | packages/shared/src/errors.ts:304 |
received? | readonly | string | Actual 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 ​
| Parameter | Type |
|---|---|
json | SerializedAIDKError |
Returns ​
Inherited from ​
required() ​
ts
static required(field: string, message?: string): ValidationError;Defined in: packages/shared/src/errors.ts:347
Create a "required" validation error
Parameters ​
| Parameter | Type |
|---|---|
field | string |
message? | string |
Returns ​
ValidationError
toJSON() ​
ts
toJSON(): SerializedAIDKError;Defined in: packages/shared/src/errors.ts:131
Serialize error for transport (JSON-safe)
Returns ​
Inherited from ​
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 ​
| Parameter | Type |
|---|---|
field | string |
expected | string |
received? | string |
Returns ​
ValidationError