@zudojs/errors 1.3.1 → 1.3.2

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/README.md CHANGED
@@ -48,6 +48,7 @@ try {
48
48
  - `ErrorCode`, `ErrorCategory` and `ErrorSeverity` enums with guards (`isErrorCode`, ...)
49
49
  - Domain, infrastructure and system error families (access, state, HTTP, database, network, container, adapter, crypto, ...) with factories and type guards
50
50
  - Base classes for other packages' error families, so their `instanceof` checks match: `TransactionError` (+ 10 subclasses), `MiddlewareLimitExceededError` / `MiddlewareDepthExceededError` / `MiddlewareRateLimitError` / `MiddlewareAbortedError`, `TraversalLimitError`, `HttpMiddlewareError` / `HttpMiddlewarePipelineError` / `HttpRequestGuardError`, `OpenAPIError`, `AuthError`, `OAuthError` (with `ErrorCode.OAUTH_*`), `CqrsError` (+ `CommandFailedError` / `QueryFailedError`, thrown when a failed command or query result is unwrapped), `EventBusStoppedError` / `EventBusDisposedError` (re-exported by `@zudojs/events`), `ObservabilityError`, `InvalidConstantError` / `ConstantContextError`, and the `zudojs-cli` errors `CLIValidationError` / `CLIGenerationError` / `CLINotInProjectError` / `CLITemplateError`
51
+ - Serialization limit errors take `{ statusCode?, expose? }` as a third argument, so a guard can tell a client that sent too much from a server that built too much. `SerializationPayloadTooLargeError(size, maxSize)` defaults to an exposed 413 (its message names only the two sizes, so `serializePublicError` returns it instead of "An unexpected error occurred."); pass `{ statusCode: 500, expose: false }` for a payload the server built itself, as `serialize` in `@zudojs/serialization` does. `SerializationDepthError(depth, maxDepth)` defaults to an unexposed 500; guards over untrusted input pass `{ statusCode: 400, expose: true }`
51
52
  - `withMetadata()` copies any error (including subclasses with custom constructors) with extra metadata
52
53
  - Serialization: `toJSON()`/`toLogObject()` for trusted logs (cycle-safe cause chains truncated with `"[MaxDepth]"` after 8 levels across the whole chain; metadata under sensitive keys, sensitive keys in object causes and submitted issue values are redacted, so `JSON.stringify(error)` is safe to log), `serializePublicError` / `ErrorSerializer` / `ErrorHandler.toPublicResult` for untrusted clients (recursive redaction, metadata allow-list)
53
54
  - Metadata utilities: `createErrorMetadata`, `mergeErrorMetadata`, `sanitizeErrorMetadata` (drops unsupported values) and `redactErrorMetadata` (removes secrets)
@@ -3,5 +3,6 @@
3
3
  */
4
4
  export { SerializationError, createSerializationError, isSerializationError, toSerializationError, } from "./serializationError.base.js";
5
5
  export type { SerializationErrorOptions } from "./serializationError.base.js";
6
- export { SerializeError, DeserializeError, UnsupportedSerializationFormatError, SerializerNotFoundError, CircularReferenceError, SerializationDepthError, SerializationPayloadTooLargeError, InvalidSerializedDataError, TransformerError, TransformerNotFoundError, } from "./serializationError.types.js";
6
+ export { SerializeError, DeserializeError, UnsupportedSerializationFormatError, SerializerNotFoundError, CircularReferenceError, InvalidSerializedDataError, TransformerError, TransformerNotFoundError, } from "./serializationError.types.js";
7
+ export { SerializationDepthError, SerializationPayloadTooLargeError, } from "./serializationError.limits.js";
7
8
  //# sourceMappingURL=serialization.error.d.ts.map
@@ -2,5 +2,6 @@
2
2
  * Serialization error classes — re-exports from focused files.
3
3
  */
4
4
  export { SerializationError, createSerializationError, isSerializationError, toSerializationError, } from "./serializationError.base.js";
5
- export { SerializeError, DeserializeError, UnsupportedSerializationFormatError, SerializerNotFoundError, CircularReferenceError, SerializationDepthError, SerializationPayloadTooLargeError, InvalidSerializedDataError, TransformerError, TransformerNotFoundError, } from "./serializationError.types.js";
5
+ export { SerializeError, DeserializeError, UnsupportedSerializationFormatError, SerializerNotFoundError, CircularReferenceError, InvalidSerializedDataError, TransformerError, TransformerNotFoundError, } from "./serializationError.types.js";
6
+ export { SerializationDepthError, SerializationPayloadTooLargeError, } from "./serializationError.limits.js";
6
7
  //# sourceMappingURL=serialization.error.js.map
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Serialization limit errors: a payload nested too deep or too large.
3
+ *
4
+ * Both take `{ statusCode?, expose? }` so a guard can tell a client that
5
+ * sent too much (an exposed 4xx) from a server that built too much (an
6
+ * unexposed 500). Their messages hold only the observed value and the
7
+ * limit, never the payload.
8
+ */
9
+ import { SerializationError } from "./serializationError.base.js";
10
+ /** Status and exposure overrides accepted by the limit errors. */
11
+ export interface SerializationLimitErrorOptions {
12
+ readonly statusCode?: number;
13
+ readonly expose?: boolean;
14
+ }
15
+ /**
16
+ * Error thrown when maximum serialization depth is exceeded.
17
+ *
18
+ * By default over-deep data is a server-side data bug, so this is an
19
+ * internal (500) error. Code that checks UNTRUSTED input (for example
20
+ * `assertDepthWithinLimit` in `@zudojs/validation`) passes
21
+ * `{ statusCode: 400, expose: true }`: too-deep client input is a client
22
+ * error. The message holds only the two numbers, so it is safe to expose.
23
+ */
24
+ export declare class SerializationDepthError extends SerializationError {
25
+ readonly depth: number;
26
+ readonly maxDepth: number;
27
+ /** @deprecated Use `maxDepth`. */
28
+ readonly maxDepthValue: number;
29
+ constructor(depth: number, maxDepth: number, options?: SerializationLimitErrorOptions);
30
+ }
31
+ /**
32
+ * Error thrown when a serialized payload exceeds the size limit.
33
+ *
34
+ * By default this is an exposed 413: the size guards that throw it
35
+ * (`deserialize` in `@zudojs/serialization`, `assertSizeWithinLimit` in
36
+ * `@zudojs/validation`) check UNTRUSTED input, and too much client input is
37
+ * a client error. It used to be an unexposed 413, which
38
+ * `serializePublicError` answered with "An unexpected error occurred.".
39
+ * The message holds only the two sizes, never the payload, so it is safe to
40
+ * expose. Code that checks a payload the server built itself passes
41
+ * `{ statusCode: 500, expose: false }`, as `serialize` does.
42
+ */
43
+ export declare class SerializationPayloadTooLargeError extends SerializationError {
44
+ readonly size: number;
45
+ readonly maxSize: number;
46
+ /** @deprecated Use `size`. */
47
+ readonly payloadSize: number;
48
+ /** @deprecated Use `maxSize`. */
49
+ readonly maxSizeValue: number;
50
+ constructor(size: number, maxSize: number, options?: SerializationLimitErrorOptions);
51
+ }
52
+ //# sourceMappingURL=serializationError.limits.d.ts.map
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Serialization limit errors: a payload nested too deep or too large.
3
+ *
4
+ * Both take `{ statusCode?, expose? }` so a guard can tell a client that
5
+ * sent too much (an exposed 4xx) from a server that built too much (an
6
+ * unexposed 500). Their messages hold only the observed value and the
7
+ * limit, never the payload.
8
+ */
9
+ import { ErrorCode } from "../../base/types/errorCode.type.js";
10
+ import { SerializationError } from "./serializationError.base.js";
11
+ /**
12
+ * Error thrown when maximum serialization depth is exceeded.
13
+ *
14
+ * By default over-deep data is a server-side data bug, so this is an
15
+ * internal (500) error. Code that checks UNTRUSTED input (for example
16
+ * `assertDepthWithinLimit` in `@zudojs/validation`) passes
17
+ * `{ statusCode: 400, expose: true }`: too-deep client input is a client
18
+ * error. The message holds only the two numbers, so it is safe to expose.
19
+ */
20
+ export class SerializationDepthError extends SerializationError {
21
+ depth;
22
+ maxDepth;
23
+ /** @deprecated Use `maxDepth`. */
24
+ maxDepthValue;
25
+ constructor(depth, maxDepth, options = {}) {
26
+ super(`Maximum serialization depth exceeded: ${depth} > ${maxDepth}`, {
27
+ code: ErrorCode.MAX_DEPTH_EXCEEDED,
28
+ depth,
29
+ maxDepth,
30
+ statusCode: options.statusCode ?? 500,
31
+ expose: options.expose ?? false,
32
+ });
33
+ this.depth = depth;
34
+ this.maxDepth = maxDepth;
35
+ this.maxDepthValue = maxDepth;
36
+ }
37
+ }
38
+ /**
39
+ * Error thrown when a serialized payload exceeds the size limit.
40
+ *
41
+ * By default this is an exposed 413: the size guards that throw it
42
+ * (`deserialize` in `@zudojs/serialization`, `assertSizeWithinLimit` in
43
+ * `@zudojs/validation`) check UNTRUSTED input, and too much client input is
44
+ * a client error. It used to be an unexposed 413, which
45
+ * `serializePublicError` answered with "An unexpected error occurred.".
46
+ * The message holds only the two sizes, never the payload, so it is safe to
47
+ * expose. Code that checks a payload the server built itself passes
48
+ * `{ statusCode: 500, expose: false }`, as `serialize` does.
49
+ */
50
+ export class SerializationPayloadTooLargeError extends SerializationError {
51
+ size;
52
+ maxSize;
53
+ /** @deprecated Use `size`. */
54
+ payloadSize;
55
+ /** @deprecated Use `maxSize`. */
56
+ maxSizeValue;
57
+ constructor(size, maxSize, options = {}) {
58
+ super(`Serialized payload too large: ${size} bytes (max: ${maxSize})`, {
59
+ code: ErrorCode.PAYLOAD_TOO_LARGE,
60
+ size,
61
+ maxSize,
62
+ statusCode: options.statusCode ?? 413,
63
+ expose: options.expose ?? true,
64
+ });
65
+ this.size = size;
66
+ this.maxSize = maxSize;
67
+ this.payloadSize = size;
68
+ this.maxSizeValue = maxSize;
69
+ }
70
+ }
71
+ //# sourceMappingURL=serializationError.limits.js.map
@@ -39,35 +39,6 @@ export declare class CircularReferenceError extends SerializationError {
39
39
  readonly circularPath: string;
40
40
  constructor(path?: string);
41
41
  }
42
- /**
43
- * Error thrown when maximum serialization depth is exceeded.
44
- *
45
- * By default over-deep data is a server-side data bug, so this is an
46
- * internal (500) error. Code that checks UNTRUSTED input (for example
47
- * `assertDepthWithinLimit` in `@zudojs/validation`) passes
48
- * `{ statusCode: 400, expose: true }`: too-deep client input is a client
49
- * error. The message holds only the two numbers, so it is safe to expose.
50
- */
51
- export declare class SerializationDepthError extends SerializationError {
52
- readonly depth: number;
53
- readonly maxDepth: number;
54
- /** @deprecated Use `maxDepth`. */
55
- readonly maxDepthValue: number;
56
- constructor(depth: number, maxDepth: number, options?: {
57
- readonly statusCode?: number;
58
- readonly expose?: boolean;
59
- });
60
- }
61
- /** Error thrown when a serialized payload exceeds the size limit. */
62
- export declare class SerializationPayloadTooLargeError extends SerializationError {
63
- readonly size: number;
64
- readonly maxSize: number;
65
- /** @deprecated Use `size`. */
66
- readonly payloadSize: number;
67
- /** @deprecated Use `maxSize`. */
68
- readonly maxSizeValue: number;
69
- constructor(size: number, maxSize: number);
70
- }
71
42
  /** Error thrown when serialized data is invalid or malformed. */
72
43
  export declare class InvalidSerializedDataError extends SerializationError {
73
44
  constructor(message: string, options?: {
@@ -71,55 +71,6 @@ export class CircularReferenceError extends SerializationError {
71
71
  this.circularPath = path;
72
72
  }
73
73
  }
74
- /**
75
- * Error thrown when maximum serialization depth is exceeded.
76
- *
77
- * By default over-deep data is a server-side data bug, so this is an
78
- * internal (500) error. Code that checks UNTRUSTED input (for example
79
- * `assertDepthWithinLimit` in `@zudojs/validation`) passes
80
- * `{ statusCode: 400, expose: true }`: too-deep client input is a client
81
- * error. The message holds only the two numbers, so it is safe to expose.
82
- */
83
- export class SerializationDepthError extends SerializationError {
84
- depth;
85
- maxDepth;
86
- /** @deprecated Use `maxDepth`. */
87
- maxDepthValue;
88
- constructor(depth, maxDepth, options = {}) {
89
- super(`Maximum serialization depth exceeded: ${depth} > ${maxDepth}`, {
90
- code: ErrorCode.MAX_DEPTH_EXCEEDED,
91
- depth,
92
- maxDepth,
93
- statusCode: options.statusCode ?? 500,
94
- expose: options.expose ?? false,
95
- });
96
- this.depth = depth;
97
- this.maxDepth = maxDepth;
98
- this.maxDepthValue = maxDepth;
99
- }
100
- }
101
- /** Error thrown when a serialized payload exceeds the size limit. */
102
- export class SerializationPayloadTooLargeError extends SerializationError {
103
- size;
104
- maxSize;
105
- /** @deprecated Use `size`. */
106
- payloadSize;
107
- /** @deprecated Use `maxSize`. */
108
- maxSizeValue;
109
- constructor(size, maxSize) {
110
- super(`Serialized payload too large: ${size} bytes (max: ${maxSize})`, {
111
- code: ErrorCode.PAYLOAD_TOO_LARGE,
112
- size,
113
- maxSize,
114
- statusCode: 413,
115
- expose: false,
116
- });
117
- this.size = size;
118
- this.maxSize = maxSize;
119
- this.payloadSize = size;
120
- this.maxSizeValue = maxSize;
121
- }
122
- }
123
74
  /** Error thrown when serialized data is invalid or malformed. */
124
75
  export class InvalidSerializedDataError extends SerializationError {
125
76
  constructor(message, options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zudojs/errors",
3
- "version": "1.3.1",
3
+ "version": "1.3.2",
4
4
  "description": "Shared error base class, error codes, and error handling utilities for the Zudojs framework.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",