@ultimat3/schema 4.1.0 → 5.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/errors.ts +13 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ultimat3/schema",
3
- "version": "4.1.0",
3
+ "version": "5.0.1",
4
4
  "description": "Ultimate's validation seam: Standard Schema interface, the t namespace, JSON Schema output",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/src/errors.ts CHANGED
@@ -96,22 +96,24 @@ export class SchemaError extends Error {
96
96
  readonly meta: Readonly<Record<string, unknown>> | undefined;
97
97
 
98
98
  constructor(init: SchemaErrorInit) {
99
- const title = TITLES[init.code] ?? humanize(init.code);
100
- super(`${init.code}: ${title}`, { cause: init.cause });
101
- this.code = init.code;
99
+ // Escaped HERE, once, exactly as `UltimateError`'s constructor does — read the reason there.
100
+ // A schema cause is the one most likely to carry a hostile string: it describes the value that
101
+ // failed validation, which is the request body.
102
+ const code = singleLine(init.code);
103
+ const title = singleLine(TITLES[init.code] ?? humanize(init.code));
104
+ super(`${code}: ${title}`, { cause: singleLine(init.cause) });
105
+ this.code = code;
102
106
  this.title = title;
103
- this.fix = init.fix;
104
- this.docs = init.docs ?? `https://ultimate.dev/errors/${init.code}`;
107
+ this.fix = singleLine(init.fix);
108
+ this.docs = singleLine(init.docs ?? `https://ultimate.dev/errors/${init.code}`);
105
109
  this.meta = init.meta;
106
110
  }
107
111
 
108
- /** The same 3-line rendering as `UltimateError.format()`. */
112
+ /** The same 3-line rendering as `UltimateError.format()`, escaped in the same place: neither. */
109
113
  format(): string {
110
- return [
111
- `${singleLine(this.code)}: ${singleLine(this.title)}`,
112
- ` cause: ${singleLine(this.cause)}`,
113
- ` fix: ${singleLine(this.fix)}`,
114
- ].join('\n');
114
+ return [`${this.code}: ${this.title}`, ` cause: ${this.cause}`, ` fix: ${this.fix}`].join(
115
+ '\n',
116
+ );
115
117
  }
116
118
 
117
119
  toJSON(): SchemaErrorJSON {