@pcvl/schema / Issue
Class: Issue
Defined in: issue/issue.ts:43
One reason a value was rejected: a machine-matchable IssueCode, a human-readable message, and — for a failure inside an object, array or nested combination of the two — the path to where it happened. A failure reported at the root may omit path entirely.
Example
ts
import { pvl, type Issue } from '@pcvl/schema';
const result = pvl.object({ name: pvl.string() }).validate({ name: 42 });
if (result.issues) {
const issue: Issue = result.issues[0]!;
console.log(issue.code, issue.path, issue.message);
// 'INVALID_TYPE' [ 'name' ] 'Expected string'
}Implements
Issue
Properties
code
ts
code:
| "INVALID_TYPE"
| "INVALID_VALUE"
| "TOO_SMALL"
| "TOO_BIG"
| "INVALID_LENGTH"
| "NOT_INTEGER"
| "UNRECOGNIZED_KEY"
| "INVALID_UNION"
| "CUSTOM";Defined in: issue/issue.ts:55
Which check failed, as one of the ISSUE_CODE values.
Example
ts
import { ISSUE_CODE, pvl } from '@pcvl/schema';
const result = pvl.number().int().validate(1.5);
result.issues?.[0]?.code === ISSUE_CODE.NOT_INTEGER; // truemessage
ts
message: string;Defined in: issue/issue.ts:68
A human-readable description of the failure: the check's default, or the { message } passed to the Modifier that reported it.
Example
ts
import { pvl } from '@pcvl/schema';
const result = pvl.string().min(3, { message: 'too short' }).validate('hi');
result.issues?.[0]?.message; // 'too short'Implementation of
ts
StandardSchemaV1.Issue.messagepath
ts
path: readonly PropertyKey[] | undefined = undefined;Defined in: issue/issue.ts:81
Where in the validated value the failure is: object keys and array indices from the root. undefined for a failure at the root itself.
Example
ts
import { pvl } from '@pcvl/schema';
const result = pvl.object({ tags: pvl.array(pvl.string()) }).validate({ tags: ['a', 1] });
result.issues?.[0]?.path; // ['tags', 1]Implementation of
ts
StandardSchemaV1.Issue.path