@dxos/errors 0.8.4-main.dedc0f3 → 0.8.4-main.e098934

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.
@@ -57,33 +57,38 @@ var _context = /* @__PURE__ */ new WeakMap();
57
57
  var BaseError = class _BaseError extends Error {
58
58
  /**
59
59
  * Primary way of defining new error classes.
60
- *
61
- * Expample:
62
- *
63
- * ```ts
64
- * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
65
- * ```
60
+ * Extended class may specialize constructor for required context params.
61
+ * @param code - Error code.
62
+ * @param message - Default error message.
66
63
  */
67
- static extend(code) {
64
+ static extend(code, message) {
68
65
  var _class;
69
66
  return _class = class extends _BaseError {
70
67
  static is(error) {
71
68
  return typeof error === "object" && error !== null && "code" in error && error.code === code;
72
69
  }
73
- static wrap(message, options) {
74
- return (error) => new this(message, {
70
+ static wrap(options) {
71
+ return (error) => new this({
72
+ message,
75
73
  ...options,
76
74
  cause: error
77
75
  });
78
76
  }
79
- constructor(message, options) {
80
- super(code, message, options);
77
+ constructor(options) {
78
+ super(code, {
79
+ message: options?.message ?? message,
80
+ ...options
81
+ });
81
82
  }
82
83
  }, _define_property(_class, "code", code), _class;
83
84
  }
84
85
  get name() {
85
86
  return _class_private_field_get(this, _code);
86
87
  }
88
+ /** Fallback message. */
89
+ get message() {
90
+ return this.constructor.name;
91
+ }
87
92
  get code() {
88
93
  return _class_private_field_get(this, _code);
89
94
  }
@@ -94,8 +99,10 @@ var BaseError = class _BaseError extends Error {
94
99
  get context() {
95
100
  return _class_private_field_get(this, _context);
96
101
  }
97
- constructor(code, message, options) {
98
- super(message, options), _class_private_field_init(this, _code, {
102
+ constructor(code, options) {
103
+ super(options?.message, {
104
+ cause: options?.cause
105
+ }), _class_private_field_init(this, _code, {
99
106
  writable: true,
100
107
  value: void 0
101
108
  }), _class_private_field_init(this, _context, {
@@ -109,25 +116,25 @@ var BaseError = class _BaseError extends Error {
109
116
  };
110
117
 
111
118
  // src/errors.ts
112
- var TimeoutError = class extends BaseError.extend("TIMEOUT") {
119
+ var ApiError = class extends BaseError.extend("API", "API error") {
113
120
  };
114
- var AbortedError = class extends BaseError.extend("ABORTED") {
121
+ var SystemError = class extends BaseError.extend("SYSTEM", "System error") {
115
122
  };
116
- var UnimplementedError = class extends BaseError.extend("UNIMPLEMENTED") {
123
+ var InternalError = class extends BaseError.extend("INTERNAL", "Internal error") {
117
124
  };
118
- var ApiError = class extends BaseError.extend("API_ERROR") {
125
+ var TimeoutError = class extends BaseError.extend("TIMEOUT", "Timeout") {
119
126
  };
120
- var SystemError = class extends BaseError.extend("SYSTEM_ERROR") {
127
+ var AbortedError = class extends BaseError.extend("ABORTED", "Aborted") {
121
128
  };
122
- var InternalError = class extends BaseError.extend("INTERNAL_ERROR") {
129
+ var NotImplementedError = class extends BaseError.extend("NOT_IMPLEMENTED", "Not implemented") {
123
130
  };
124
131
  export {
125
132
  AbortedError,
126
133
  ApiError,
127
134
  BaseError,
128
135
  InternalError,
136
+ NotImplementedError,
129
137
  SystemError,
130
- TimeoutError,
131
- UnimplementedError
138
+ TimeoutError
132
139
  };
133
140
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/base.ts", "../../../src/errors.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport type BaseErrorOptions = {\n /**\n * The cause of the error.\n * An instance of Error.\n */\n cause?: unknown;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Code extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n *\n * Expample:\n *\n * ```ts\n * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}\n * ```\n */\n static extend<Code extends string>(code: Code) {\n return class extends BaseError<Code> {\n static code = code;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === code;\n }\n\n static wrap(message: string, options?: Omit<BaseErrorOptions, 'cause'>) {\n return (error: unknown) => new this(message, { ...options, cause: error });\n }\n\n constructor(message: string, options?: BaseErrorOptions) {\n super(code, message, options);\n }\n };\n }\n\n #code: Code;\n #context: Record<string, unknown>;\n\n constructor(code: Code, message: string, options?: BaseErrorOptions) {\n super(message, options);\n\n this.#code = code;\n this.#context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n override get name() {\n return this.#code;\n }\n\n get code(): Code {\n return this.#code;\n }\n\n // For effect error matching.\n get _tag(): Code {\n return this.#code;\n }\n\n get context() {\n return this.#context;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class TimeoutError extends BaseError.extend('TIMEOUT') {}\n\nexport class AbortedError extends BaseError.extend('ABORTED') {}\n\nexport class UnimplementedError extends BaseError.extend('UNIMPLEMENTED') {}\n\nexport class ApiError extends BaseError.extend('API_ERROR') {}\n\nexport class SystemError extends BaseError.extend('SYSTEM_ERROR') {}\n\nexport class InternalError extends BaseError.extend('INTERNAL_ERROR') {}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgDE,QAAA,oBAAA,QAAA;IACA,WAAA,oBAAA,QAAA;AA7BK,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;;;;EAU3D,OAAOC,OAA4BC,MAAY;;AAC7C,WAAA,SAAO,cAAcH,WAAAA;MAGnB,OAAOI,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMF,SAASA;MAC1F;MAEA,OAAOG,KAAKC,SAAiBC,SAA2C;AACtE,eAAO,CAACH,UAAmB,IAAI,KAAKE,SAAS;UAAE,GAAGC;UAASC,OAAOJ;QAAM,CAAA;MAC1E;MAEA,YAAYE,SAAiBC,SAA4B;AACvD,cAAML,MAAMI,SAASC,OAAAA;MACvB;IACF,GAbE,iBAAA,QAAOL,QAAOA,IAAAA,GAAAA;EAclB;EAaA,IAAaO,OAAO;AAClB,WAAA,yBAAO,MAAK,KAAA;EACd;EAEA,IAAIP,OAAa;AACf,WAAA,yBAAO,MAAK,KAAA;EACd;;EAGA,IAAIQ,OAAa;AACf,WAAA,yBAAO,MAAK,KAAA;EACd;EAEA,IAAIC,UAAU;AACZ,WAAA,yBAAO,MAAK,QAAA;EACd;EAvBA,YAAYT,MAAYI,SAAiBC,SAA4B;AACnE,UAAMD,SAASC,OAAAA,GAJjB,0BAAA,MAAA,OAAA;;aAAA;QACA,0BAAA,MAAA,UAAA;;aAAA;;mCAKO,OAAQL,IAAAA;mCACR,UAAWK,SAASI,WAAW,CAAC,CAAA;AACrCC,WAAOC,eAAe,MAAM,WAAWC,SAAS;EAClD;AAkBF;;;ACrEO,IAAMC,eAAN,cAA2BC,UAAUC,OAAO,SAAA,EAAA;AAAY;AAExD,IAAMC,eAAN,cAA2BF,UAAUC,OAAO,SAAA,EAAA;AAAY;AAExD,IAAME,qBAAN,cAAiCH,UAAUC,OAAO,eAAA,EAAA;AAAkB;AAEpE,IAAMG,WAAN,cAAuBJ,UAAUC,OAAO,WAAA,EAAA;AAAc;AAEtD,IAAMI,cAAN,cAA0BL,UAAUC,OAAO,cAAA,EAAA;AAAiB;AAE5D,IAAMK,gBAAN,cAA4BN,UAAUC,OAAO,gBAAA,EAAA;AAAmB;",
6
- "names": ["BaseError", "Error", "extend", "code", "is", "error", "wrap", "message", "options", "cause", "name", "_tag", "context", "Object", "setPrototypeOf", "prototype", "TimeoutError", "BaseError", "extend", "AbortedError", "UnimplementedError", "ApiError", "SystemError", "InternalError"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Options for creating a BaseError.\n */\nexport type BaseErrorOptions = ErrorOptions & {\n /**\n * Override base message.\n */\n message?: string;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Code extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n * Extended class may specialize constructor for required context params.\n * @param code - Error code.\n * @param message - Default error message.\n */\n static extend<Code extends string = string>(code: Code, message?: string) {\n return class extends BaseError<Code> {\n static code = code;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === code;\n }\n\n static wrap(options?: Omit<BaseErrorOptions, 'cause'>) {\n return (error: unknown) => new this({ message, ...options, cause: error });\n }\n\n constructor(options?: BaseErrorOptions) {\n super(code, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n #code: Code;\n #context: Record<string, unknown>;\n\n constructor(code: Code, options?: BaseErrorOptions) {\n super(options?.message, { cause: options?.cause });\n\n this.#code = code;\n this.#context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n override get name() {\n return this.#code;\n }\n\n /** Fallback message. */\n override get message() {\n return this.constructor.name;\n }\n\n get code(): Code {\n return this.#code;\n }\n\n // For effect error matching.\n get _tag(): Code {\n return this.#code;\n }\n\n get context() {\n return this.#context;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class ApiError extends BaseError.extend('API', 'API error') {}\n\nexport class SystemError extends BaseError.extend('SYSTEM', 'System error') {}\n\nexport class InternalError extends BaseError.extend('INTERNAL', 'Internal error') {}\n\nexport class TimeoutError extends BaseError.extend('TIMEOUT', 'Timeout') {}\n\nexport class AbortedError extends BaseError.extend('ABORTED', 'Aborted') {}\n\nexport class NotImplementedError extends BaseError.extend('NOT_IMPLEMENTED', 'Not implemented') {}\n"],
5
+ "mappings": ";AAMC,SAAA,6BAAA,KAAA,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAyCC,QAAA,oBAAA,QAAA;IACA,WAAA,oBAAA,QAA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AAA,EAAA;AAAmB;AAE5E,IAAMG,eAAN,cAA2BJ,UAAUC,OAAO,WAAW,SAAA,EAAA;AAAY;AAEnE,IAAMI,eAAN,cAA2BL,UAAUC,OAAO,WAAW,SAAA,EAAA;AAAY;AAEnE,IAAMK,sBAAN,cAAkCN,UAAUC,OAAO,mBAAmB,iBAAA,EAAA;AAAoB;",
6
+ "names": ["BaseError", "Error", "extend", "code", "message", "is", "error", "wrap", "options", "cause", "name", "_tag", "context", "Object", "setPrototypeOf", "prototype", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/base.ts":{"bytes":7660,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2000,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":523,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3885},"dist/lib/browser/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","SystemError","TimeoutError","UnimplementedError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":3300},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":418}},"bytes":3908}}}
1
+ {"inputs":{"src/base.ts":{"bytes":8342,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2213,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":523,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4277},"dist/lib/browser/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":3482},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":491}},"bytes":4164}}}
@@ -59,33 +59,38 @@ var _context = /* @__PURE__ */ new WeakMap();
59
59
  var BaseError = class _BaseError extends Error {
60
60
  /**
61
61
  * Primary way of defining new error classes.
62
- *
63
- * Expample:
64
- *
65
- * ```ts
66
- * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
67
- * ```
62
+ * Extended class may specialize constructor for required context params.
63
+ * @param code - Error code.
64
+ * @param message - Default error message.
68
65
  */
69
- static extend(code) {
66
+ static extend(code, message) {
70
67
  var _class;
71
68
  return _class = class extends _BaseError {
72
69
  static is(error) {
73
70
  return typeof error === "object" && error !== null && "code" in error && error.code === code;
74
71
  }
75
- static wrap(message, options) {
76
- return (error) => new this(message, {
72
+ static wrap(options) {
73
+ return (error) => new this({
74
+ message,
77
75
  ...options,
78
76
  cause: error
79
77
  });
80
78
  }
81
- constructor(message, options) {
82
- super(code, message, options);
79
+ constructor(options) {
80
+ super(code, {
81
+ message: options?.message ?? message,
82
+ ...options
83
+ });
83
84
  }
84
85
  }, _define_property(_class, "code", code), _class;
85
86
  }
86
87
  get name() {
87
88
  return _class_private_field_get(this, _code);
88
89
  }
90
+ /** Fallback message. */
91
+ get message() {
92
+ return this.constructor.name;
93
+ }
89
94
  get code() {
90
95
  return _class_private_field_get(this, _code);
91
96
  }
@@ -96,8 +101,10 @@ var BaseError = class _BaseError extends Error {
96
101
  get context() {
97
102
  return _class_private_field_get(this, _context);
98
103
  }
99
- constructor(code, message, options) {
100
- super(message, options), _class_private_field_init(this, _code, {
104
+ constructor(code, options) {
105
+ super(options?.message, {
106
+ cause: options?.cause
107
+ }), _class_private_field_init(this, _code, {
101
108
  writable: true,
102
109
  value: void 0
103
110
  }), _class_private_field_init(this, _context, {
@@ -111,25 +118,25 @@ var BaseError = class _BaseError extends Error {
111
118
  };
112
119
 
113
120
  // src/errors.ts
114
- var TimeoutError = class extends BaseError.extend("TIMEOUT") {
121
+ var ApiError = class extends BaseError.extend("API", "API error") {
115
122
  };
116
- var AbortedError = class extends BaseError.extend("ABORTED") {
123
+ var SystemError = class extends BaseError.extend("SYSTEM", "System error") {
117
124
  };
118
- var UnimplementedError = class extends BaseError.extend("UNIMPLEMENTED") {
125
+ var InternalError = class extends BaseError.extend("INTERNAL", "Internal error") {
119
126
  };
120
- var ApiError = class extends BaseError.extend("API_ERROR") {
127
+ var TimeoutError = class extends BaseError.extend("TIMEOUT", "Timeout") {
121
128
  };
122
- var SystemError = class extends BaseError.extend("SYSTEM_ERROR") {
129
+ var AbortedError = class extends BaseError.extend("ABORTED", "Aborted") {
123
130
  };
124
- var InternalError = class extends BaseError.extend("INTERNAL_ERROR") {
131
+ var NotImplementedError = class extends BaseError.extend("NOT_IMPLEMENTED", "Not implemented") {
125
132
  };
126
133
  export {
127
134
  AbortedError,
128
135
  ApiError,
129
136
  BaseError,
130
137
  InternalError,
138
+ NotImplementedError,
131
139
  SystemError,
132
- TimeoutError,
133
- UnimplementedError
140
+ TimeoutError
134
141
  };
135
142
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/base.ts", "../../../src/errors.ts"],
4
- "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nexport type BaseErrorOptions = {\n /**\n * The cause of the error.\n * An instance of Error.\n */\n cause?: unknown;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Code extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n *\n * Expample:\n *\n * ```ts\n * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}\n * ```\n */\n static extend<Code extends string>(code: Code) {\n return class extends BaseError<Code> {\n static code = code;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === code;\n }\n\n static wrap(message: string, options?: Omit<BaseErrorOptions, 'cause'>) {\n return (error: unknown) => new this(message, { ...options, cause: error });\n }\n\n constructor(message: string, options?: BaseErrorOptions) {\n super(code, message, options);\n }\n };\n }\n\n #code: Code;\n #context: Record<string, unknown>;\n\n constructor(code: Code, message: string, options?: BaseErrorOptions) {\n super(message, options);\n\n this.#code = code;\n this.#context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n override get name() {\n return this.#code;\n }\n\n get code(): Code {\n return this.#code;\n }\n\n // For effect error matching.\n get _tag(): Code {\n return this.#code;\n }\n\n get context() {\n return this.#context;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class TimeoutError extends BaseError.extend('TIMEOUT') {}\n\nexport class AbortedError extends BaseError.extend('ABORTED') {}\n\nexport class UnimplementedError extends BaseError.extend('UNIMPLEMENTED') {}\n\nexport class ApiError extends BaseError.extend('API_ERROR') {}\n\nexport class SystemError extends BaseError.extend('SYSTEM_ERROR') {}\n\nexport class InternalError extends BaseError.extend('INTERNAL_ERROR') {}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgDE,QAAA,oBAAA,QAAA;IACA,WAAA,oBAAA,QAAA;AA7BK,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;;;;EAU3D,OAAOC,OAA4BC,MAAY;;AAC7C,WAAA,SAAO,cAAcH,WAAAA;MAGnB,OAAOI,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMF,SAASA;MAC1F;MAEA,OAAOG,KAAKC,SAAiBC,SAA2C;AACtE,eAAO,CAACH,UAAmB,IAAI,KAAKE,SAAS;UAAE,GAAGC;UAASC,OAAOJ;QAAM,CAAA;MAC1E;MAEA,YAAYE,SAAiBC,SAA4B;AACvD,cAAML,MAAMI,SAASC,OAAAA;MACvB;IACF,GAbE,iBAAA,QAAOL,QAAOA,IAAAA,GAAAA;EAclB;EAaA,IAAaO,OAAO;AAClB,WAAA,yBAAO,MAAK,KAAA;EACd;EAEA,IAAIP,OAAa;AACf,WAAA,yBAAO,MAAK,KAAA;EACd;;EAGA,IAAIQ,OAAa;AACf,WAAA,yBAAO,MAAK,KAAA;EACd;EAEA,IAAIC,UAAU;AACZ,WAAA,yBAAO,MAAK,QAAA;EACd;EAvBA,YAAYT,MAAYI,SAAiBC,SAA4B;AACnE,UAAMD,SAASC,OAAAA,GAJjB,0BAAA,MAAA,OAAA;;aAAA;QACA,0BAAA,MAAA,UAAA;;aAAA;;mCAKO,OAAQL,IAAAA;mCACR,UAAWK,SAASI,WAAW,CAAC,CAAA;AACrCC,WAAOC,eAAe,MAAM,WAAWC,SAAS;EAClD;AAkBF;;;ACrEO,IAAMC,eAAN,cAA2BC,UAAUC,OAAO,SAAA,EAAA;AAAY;AAExD,IAAMC,eAAN,cAA2BF,UAAUC,OAAO,SAAA,EAAA;AAAY;AAExD,IAAME,qBAAN,cAAiCH,UAAUC,OAAO,eAAA,EAAA;AAAkB;AAEpE,IAAMG,WAAN,cAAuBJ,UAAUC,OAAO,WAAA,EAAA;AAAc;AAEtD,IAAMI,cAAN,cAA0BL,UAAUC,OAAO,cAAA,EAAA;AAAiB;AAE5D,IAAMK,gBAAN,cAA4BN,UAAUC,OAAO,gBAAA,EAAA;AAAmB;",
6
- "names": ["BaseError", "Error", "extend", "code", "is", "error", "wrap", "message", "options", "cause", "name", "_tag", "context", "Object", "setPrototypeOf", "prototype", "TimeoutError", "BaseError", "extend", "AbortedError", "UnimplementedError", "ApiError", "SystemError", "InternalError"]
4
+ "sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\n/**\n * Options for creating a BaseError.\n */\nexport type BaseErrorOptions = ErrorOptions & {\n /**\n * Override base message.\n */\n message?: string;\n\n /**\n * Structured details about the error.\n */\n context?: Record<string, unknown>;\n};\n\n/**\n * Base class for all DXOS errors.\n */\nexport class BaseError<Code extends string = string> extends Error {\n /**\n * Primary way of defining new error classes.\n * Extended class may specialize constructor for required context params.\n * @param code - Error code.\n * @param message - Default error message.\n */\n static extend<Code extends string = string>(code: Code, message?: string) {\n return class extends BaseError<Code> {\n static code = code;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'code' in error && error.code === code;\n }\n\n static wrap(options?: Omit<BaseErrorOptions, 'cause'>) {\n return (error: unknown) => new this({ message, ...options, cause: error });\n }\n\n constructor(options?: BaseErrorOptions) {\n super(code, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n #code: Code;\n #context: Record<string, unknown>;\n\n constructor(code: Code, options?: BaseErrorOptions) {\n super(options?.message, { cause: options?.cause });\n\n this.#code = code;\n this.#context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n override get name() {\n return this.#code;\n }\n\n /** Fallback message. */\n override get message() {\n return this.constructor.name;\n }\n\n get code(): Code {\n return this.#code;\n }\n\n // For effect error matching.\n get _tag(): Code {\n return this.#code;\n }\n\n get context() {\n return this.#context;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class ApiError extends BaseError.extend('API', 'API error') {}\n\nexport class SystemError extends BaseError.extend('SYSTEM', 'System error') {}\n\nexport class InternalError extends BaseError.extend('INTERNAL', 'Internal error') {}\n\nexport class TimeoutError extends BaseError.extend('TIMEOUT', 'Timeout') {}\n\nexport class AbortedError extends BaseError.extend('ABORTED', 'Aborted') {}\n\nexport class NotImplementedError extends BaseError.extend('NOT_IMPLEMENTED', 'Not implemented') {}\n"],
5
+ "mappings": ";;;AAMC,SAAA,6BAAA,KAAA,mBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAyCC,QAAA,oBAAA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AA4BH,UAAUC,OAAO,YAAY,gBAAA,EAAA;AAAmB;AAE5E,IAAMG,eAAN,cAA2BJ,UAAUC,OAAO,WAAW,SAAA,EAAA;AAAY;AAEnE,IAAMI,eAAN,cAA2BL,UAAUC,OAAO,WAAW,SAAA,EAAA;AAAY;AAEnE,IAAMK,sBAAN,cAAkCN,UAAUC,OAAO,mBAAmB,iBAAA,EAAA;AAAoB;",
6
+ "names": ["BaseError", "Error", "extend", "code", "message", "is", "error", "wrap", "options", "cause", "name", "_tag", "context", "Object", "setPrototypeOf", "prototype", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"src/base.ts":{"bytes":7660,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2000,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":523,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":3887},"dist/lib/node-esm/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","SystemError","TimeoutError","UnimplementedError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":3300},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":418}},"bytes":4001}}}
1
+ {"inputs":{"src/base.ts":{"bytes":8342,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2213,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"}],"format":"esm"},"src/index.ts":{"bytes":523,"imports":[{"path":"src/base.ts","kind":"import-statement","original":"./base"},{"path":"src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":4279},"dist/lib/node-esm/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":3482},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":491}},"bytes":4257}}}
@@ -1,9 +1,11 @@
1
- export type BaseErrorOptions = {
1
+ /**
2
+ * Options for creating a BaseError.
3
+ */
4
+ export type BaseErrorOptions = ErrorOptions & {
2
5
  /**
3
- * The cause of the error.
4
- * An instance of Error.
6
+ * Override base message.
5
7
  */
6
- cause?: unknown;
8
+ message?: string;
7
9
  /**
8
10
  * Structured details about the error.
9
11
  */
@@ -16,46 +18,47 @@ export declare class BaseError<Code extends string = string> extends Error {
16
18
  #private;
17
19
  /**
18
20
  * Primary way of defining new error classes.
19
- *
20
- * Expample:
21
- *
22
- * ```ts
23
- * export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
24
- * ```
21
+ * Extended class may specialize constructor for required context params.
22
+ * @param code - Error code.
23
+ * @param message - Default error message.
25
24
  */
26
- static extend<Code extends string>(code: Code): {
27
- new (message: string, options?: BaseErrorOptions): {
25
+ static extend<Code extends string = string>(code: Code, message?: string): {
26
+ new (options?: BaseErrorOptions): {
28
27
  #code: Code;
29
28
  #context: Record<string, unknown>;
30
29
  get name(): Code;
30
+ /** Fallback message. */
31
+ get message(): string;
31
32
  get code(): Code;
32
33
  get _tag(): Code;
33
34
  get context(): Record<string, unknown>;
34
- message: string;
35
35
  stack?: string;
36
36
  cause?: unknown;
37
37
  };
38
38
  code: Code;
39
39
  is(error: unknown): error is BaseError;
40
- wrap(message: string, options?: Omit<BaseErrorOptions, "cause">): (error: unknown) => {
40
+ wrap(options?: Omit<BaseErrorOptions, "cause">): (error: unknown) => {
41
41
  #code: Code;
42
42
  #context: Record<string, unknown>;
43
43
  get name(): Code;
44
+ /** Fallback message. */
45
+ get message(): string;
44
46
  get code(): Code;
45
47
  get _tag(): Code;
46
48
  get context(): Record<string, unknown>;
47
- message: string;
48
49
  stack?: string;
49
50
  cause?: unknown;
50
51
  };
51
- extend<Code extends string>(code: Code): /*elided*/ any;
52
+ extend<Code extends string = string>(code: Code, message?: string): /*elided*/ any;
52
53
  isError(error: unknown): error is Error;
53
54
  captureStackTrace(targetObject: object, constructorOpt?: Function): void;
54
55
  prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
55
56
  stackTraceLimit: number;
56
57
  };
57
- constructor(code: Code, message: string, options?: BaseErrorOptions);
58
+ constructor(code: Code, options?: BaseErrorOptions);
58
59
  get name(): Code;
60
+ /** Fallback message. */
61
+ get message(): string;
59
62
  get code(): Code;
60
63
  get _tag(): Code;
61
64
  get context(): Record<string, unknown>;
@@ -1 +1 @@
1
- {"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/base.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,KAAK;;IAChE;;;;;;;;OAQG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,SAAS,MAAM,EAAE,IAAI,EAAE,IAAI;sBAYpB,MAAM,YAAY,gBAAgB;;sBAOjD,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;;kBAfZ,OAAO,GAAG,KAAK,IAAI,SAAS;sBAIxB,MAAM,YAAY,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,IAC5D,OAAO,OAAO;;sBAUlB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;;;;;;;;eAnBnB,IAAI,SAAS,MAAM,QAAQ,IAAI;;;;;;gBAqB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