unacy / ParseError
Class: ParseError
Defined in: packages/core/src/errors.ts:193
Error thrown when parsing a string into a format-tagged value fails.
Remarks
Thrown by Parser<T> implementations (and createParserWithSchema) when input validation fails. Carries the format name, original input, and a human-readable reason to help callers produce user-facing error messages.
Input strings longer than 50 characters are truncated with ... in the error message to keep logs readable.
Example
typescript
try {
parseISO('not-a-date');
} catch (e) {
if (e instanceof ParseError) {
console.error(`Failed to parse ${e.format}: ${e.reason}`);
console.error(`Input was: ${e.input}`);
}
}Pitfalls
NEVER catch ParseError silently and return a default value without logging — silent coercion hides data-integrity issues that may corrupt downstream state.
Extends
Constructors
Constructor
ts
new ParseError(
format,
input,
reason): ParseError;Defined in: packages/core/src/errors.ts:198
Parameters
| Parameter | Type |
|---|---|
format | string |
input | string |
reason | string |
Returns
ParseError
Overrides
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
cause? | public | unknown | UnacyError.cause | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es2022.error.d.ts:24 |
format | readonly | string | - | packages/core/src/errors.ts:194 |
input | readonly | string | - | packages/core/src/errors.ts:195 |
message | public | string | UnacyError.message | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1075 |
name | public | string | UnacyError.name | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1074 |
reason | readonly | string | - | packages/core/src/errors.ts:196 |
stack? | public | string | UnacyError.stack | node_modules/.pnpm/typescript@6.0.3/node_modules/typescript/lib/lib.es5.d.ts:1076 |