@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.
- package/package.json +1 -1
- package/src/errors.ts +13 -11
package/package.json
CHANGED
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
112
|
-
|
|
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 {
|