@dxos/errors 0.8.4-main.5ea62a8 → 0.8.4-main.72ec0f3
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/dist/lib/browser/index.mjs +50 -99
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +50 -99
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/base.d.ts +28 -28
- package/dist/types/src/base.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +174 -198
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/base.ts +37 -30
- package/src/errors.test.ts +19 -5
- package/src/errors.ts +6 -6
|
@@ -1,133 +1,84 @@
|
|
|
1
1
|
// src/base.ts
|
|
2
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
3
|
-
if (privateCollection.has(obj)) {
|
|
4
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
8
|
-
if (descriptor.get) {
|
|
9
|
-
return descriptor.get.call(receiver);
|
|
10
|
-
}
|
|
11
|
-
return descriptor.value;
|
|
12
|
-
}
|
|
13
|
-
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
14
|
-
if (descriptor.set) {
|
|
15
|
-
descriptor.set.call(receiver, value);
|
|
16
|
-
} else {
|
|
17
|
-
if (!descriptor.writable) {
|
|
18
|
-
throw new TypeError("attempted to set read only private field");
|
|
19
|
-
}
|
|
20
|
-
descriptor.value = value;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
24
|
-
if (!privateMap.has(receiver)) {
|
|
25
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
26
|
-
}
|
|
27
|
-
return privateMap.get(receiver);
|
|
28
|
-
}
|
|
29
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
30
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
31
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
32
|
-
}
|
|
33
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
34
|
-
_check_private_redeclaration(obj, privateMap);
|
|
35
|
-
privateMap.set(obj, value);
|
|
36
|
-
}
|
|
37
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
38
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
39
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
function _define_property(obj, key, value) {
|
|
43
|
-
if (key in obj) {
|
|
44
|
-
Object.defineProperty(obj, key, {
|
|
45
|
-
value,
|
|
46
|
-
enumerable: true,
|
|
47
|
-
configurable: true,
|
|
48
|
-
writable: true
|
|
49
|
-
});
|
|
50
|
-
} else {
|
|
51
|
-
obj[key] = value;
|
|
52
|
-
}
|
|
53
|
-
return obj;
|
|
54
|
-
}
|
|
55
|
-
var _code = /* @__PURE__ */ new WeakMap();
|
|
56
|
-
var _context = /* @__PURE__ */ new WeakMap();
|
|
57
2
|
var BaseError = class _BaseError extends Error {
|
|
58
3
|
/**
|
|
59
4
|
* Primary way of defining new error classes.
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* ```ts
|
|
64
|
-
* export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
|
|
65
|
-
* ```
|
|
5
|
+
* Extended class may specialize constructor for required context params.
|
|
6
|
+
* @param code - Error code.
|
|
7
|
+
* @param message - Default error message.
|
|
66
8
|
*/
|
|
67
|
-
static extend(code) {
|
|
68
|
-
|
|
69
|
-
|
|
9
|
+
static extend(code, message) {
|
|
10
|
+
return class ExtendedError extends _BaseError {
|
|
11
|
+
static code = code;
|
|
70
12
|
static is(error) {
|
|
71
13
|
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
72
14
|
}
|
|
73
|
-
static wrap(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
15
|
+
static wrap(options) {
|
|
16
|
+
const wrapFn = (error) => {
|
|
17
|
+
if (options?.ifTypeDiffers === true && this.is(error)) {
|
|
18
|
+
return error;
|
|
19
|
+
}
|
|
20
|
+
const newError = new this({
|
|
21
|
+
message,
|
|
22
|
+
...options,
|
|
23
|
+
cause: error
|
|
24
|
+
});
|
|
25
|
+
Error.captureStackTrace(newError, wrapFn);
|
|
26
|
+
return newError;
|
|
27
|
+
};
|
|
28
|
+
return wrapFn;
|
|
78
29
|
}
|
|
79
|
-
constructor(
|
|
80
|
-
super(code,
|
|
30
|
+
constructor(options) {
|
|
31
|
+
super(code, {
|
|
32
|
+
message: options?.message ?? message,
|
|
33
|
+
...options
|
|
34
|
+
});
|
|
81
35
|
}
|
|
82
|
-
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
// NOTE: Errors go through odd transformations and the private fields seem to break.
|
|
39
|
+
code;
|
|
40
|
+
context;
|
|
41
|
+
constructor(code, options) {
|
|
42
|
+
super(options?.message, {
|
|
43
|
+
cause: options?.cause
|
|
44
|
+
});
|
|
45
|
+
this.code = code;
|
|
46
|
+
this.context = options?.context ?? {};
|
|
47
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
83
48
|
}
|
|
84
49
|
get name() {
|
|
85
|
-
return
|
|
50
|
+
return this.code;
|
|
86
51
|
}
|
|
87
|
-
|
|
88
|
-
|
|
52
|
+
/** Fallback message. */
|
|
53
|
+
get message() {
|
|
54
|
+
return this.constructor.name;
|
|
89
55
|
}
|
|
90
56
|
// For effect error matching.
|
|
91
57
|
get _tag() {
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
get context() {
|
|
95
|
-
return _class_private_field_get(this, _context);
|
|
96
|
-
}
|
|
97
|
-
constructor(code, message, options) {
|
|
98
|
-
super(message, options), _class_private_field_init(this, _code, {
|
|
99
|
-
writable: true,
|
|
100
|
-
value: void 0
|
|
101
|
-
}), _class_private_field_init(this, _context, {
|
|
102
|
-
writable: true,
|
|
103
|
-
value: void 0
|
|
104
|
-
});
|
|
105
|
-
_class_private_field_set(this, _code, code);
|
|
106
|
-
_class_private_field_set(this, _context, options?.context ?? {});
|
|
107
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
58
|
+
return this.code;
|
|
108
59
|
}
|
|
109
60
|
};
|
|
110
61
|
|
|
111
62
|
// src/errors.ts
|
|
112
|
-
var
|
|
63
|
+
var ApiError = class extends BaseError.extend("API", "API error") {
|
|
113
64
|
};
|
|
114
|
-
var
|
|
65
|
+
var SystemError = class extends BaseError.extend("SYSTEM", "System error") {
|
|
115
66
|
};
|
|
116
|
-
var
|
|
67
|
+
var InternalError = class extends BaseError.extend("INTERNAL", "Internal error") {
|
|
117
68
|
};
|
|
118
|
-
var
|
|
69
|
+
var TimeoutError = class extends BaseError.extend("TIMEOUT", "Timeout") {
|
|
119
70
|
};
|
|
120
|
-
var
|
|
71
|
+
var AbortedError = class extends BaseError.extend("ABORTED", "Aborted") {
|
|
121
72
|
};
|
|
122
|
-
var
|
|
73
|
+
var NotImplementedError = class extends BaseError.extend("NOT_IMPLEMENTED", "Not implemented") {
|
|
123
74
|
};
|
|
124
75
|
export {
|
|
125
76
|
AbortedError,
|
|
126
77
|
ApiError,
|
|
127
78
|
BaseError,
|
|
128
79
|
InternalError,
|
|
80
|
+
NotImplementedError,
|
|
129
81
|
SystemError,
|
|
130
|
-
TimeoutError
|
|
131
|
-
UnimplementedError
|
|
82
|
+
TimeoutError
|
|
132
83
|
};
|
|
133
84
|
//# 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 *
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["BaseError", "Error", "extend", "code", "is", "error", "wrap", "
|
|
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 ExtendedError 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(\n options?: Omit<BaseErrorOptions, 'cause'> & { ifTypeDiffers?: boolean },\n ): (error: unknown) => ExtendedError {\n const wrapFn = (error: unknown) => {\n if (options?.ifTypeDiffers === true && this.is(error)) {\n return error as ExtendedError;\n }\n const newError: ExtendedError = new this({ message, ...options, cause: error });\n Error.captureStackTrace(newError, wrapFn); // Position stack-trace to start from the caller of `wrap`.\n return newError;\n };\n return wrapFn;\n }\n\n constructor(options?: BaseErrorOptions) {\n super(code, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n // NOTE: Errors go through odd transformations and the private fields seem to break.\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 // For effect error matching.\n get _tag(): Code {\n return this.code;\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": ";AAsBO,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;EAO3D,OAAOC,OAAqCC,MAAYC,SAAkB;AACxE,WAAO,MAAMC,sBAAsBL,WAAAA;MACjC,OAAOG,OAAOA;MAEd,OAAOG,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMJ,SAASA;MAC1F;MAEA,OAAOK,KACLC,SACmC;AACnC,cAAMC,SAAS,CAACH,UAAAA;AACd,cAAIE,SAASE,kBAAkB,QAAQ,KAAKL,GAAGC,KAAAA,GAAQ;AACrD,mBAAOA;UACT;AACA,gBAAMK,WAA0B,IAAI,KAAK;YAAER;YAAS,GAAGK;YAASI,OAAON;UAAM,CAAA;AAC7EN,gBAAMa,kBAAkBF,UAAUF,MAAAA;AAClC,iBAAOE;QACT;AACA,eAAOF;MACT;MAEA,YAAYD,SAA4B;AACtC,cAAMN,MAAM;UAAEC,SAASK,SAASL,WAAWA;UAAS,GAAGK;QAAQ,CAAA;MACjE;IACF;EACF;;EAGAN;EACAY;EAEA,YAAYZ,MAAYM,SAA4B;AAClD,UAAMA,SAASL,SAAS;MAAES,OAAOJ,SAASI;IAAM,CAAA;AAEhD,SAAKV,OAAOA;AACZ,SAAKY,UAAUN,SAASM,WAAW,CAAC;AACpCC,WAAOC,eAAe,MAAM,WAAWC,SAAS;EAClD;EAEA,IAAaC,OAAO;AAClB,WAAO,KAAKhB;EACd;;EAGA,IAAaC,UAAU;AACrB,WAAO,KAAK,YAAYe;EAC1B;;EAGA,IAAIC,OAAa;AACf,WAAO,KAAKjB;EACd;AACF;;;AC5EO,IAAMkB,WAAN,cAAuBC,UAAUC,OAAO,OAAO,WAAA,EAAA;AAAc;AAE7D,IAAMC,cAAN,cAA0BF,UAAUC,OAAO,UAAU,cAAA,EAAA;AAAiB;AAEtE,IAAME,gBAAN,cAA4BH,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", "ExtendedError", "is", "error", "wrap", "options", "wrapFn", "ifTypeDiffers", "newError", "cause", "captureStackTrace", "context", "Object", "setPrototypeOf", "prototype", "name", "_tag", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/base.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/base.ts":{"bytes":7183,"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":4645},"dist/lib/browser/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":1594},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":491}},"bytes":2276}}}
|
|
@@ -1,135 +1,86 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
|
|
3
3
|
// src/base.ts
|
|
4
|
-
function _check_private_redeclaration(obj, privateCollection) {
|
|
5
|
-
if (privateCollection.has(obj)) {
|
|
6
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
function _class_apply_descriptor_get(receiver, descriptor) {
|
|
10
|
-
if (descriptor.get) {
|
|
11
|
-
return descriptor.get.call(receiver);
|
|
12
|
-
}
|
|
13
|
-
return descriptor.value;
|
|
14
|
-
}
|
|
15
|
-
function _class_apply_descriptor_set(receiver, descriptor, value) {
|
|
16
|
-
if (descriptor.set) {
|
|
17
|
-
descriptor.set.call(receiver, value);
|
|
18
|
-
} else {
|
|
19
|
-
if (!descriptor.writable) {
|
|
20
|
-
throw new TypeError("attempted to set read only private field");
|
|
21
|
-
}
|
|
22
|
-
descriptor.value = value;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
function _class_extract_field_descriptor(receiver, privateMap, action) {
|
|
26
|
-
if (!privateMap.has(receiver)) {
|
|
27
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
28
|
-
}
|
|
29
|
-
return privateMap.get(receiver);
|
|
30
|
-
}
|
|
31
|
-
function _class_private_field_get(receiver, privateMap) {
|
|
32
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
|
|
33
|
-
return _class_apply_descriptor_get(receiver, descriptor);
|
|
34
|
-
}
|
|
35
|
-
function _class_private_field_init(obj, privateMap, value) {
|
|
36
|
-
_check_private_redeclaration(obj, privateMap);
|
|
37
|
-
privateMap.set(obj, value);
|
|
38
|
-
}
|
|
39
|
-
function _class_private_field_set(receiver, privateMap, value) {
|
|
40
|
-
var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
|
|
41
|
-
_class_apply_descriptor_set(receiver, descriptor, value);
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
function _define_property(obj, key, value) {
|
|
45
|
-
if (key in obj) {
|
|
46
|
-
Object.defineProperty(obj, key, {
|
|
47
|
-
value,
|
|
48
|
-
enumerable: true,
|
|
49
|
-
configurable: true,
|
|
50
|
-
writable: true
|
|
51
|
-
});
|
|
52
|
-
} else {
|
|
53
|
-
obj[key] = value;
|
|
54
|
-
}
|
|
55
|
-
return obj;
|
|
56
|
-
}
|
|
57
|
-
var _code = /* @__PURE__ */ new WeakMap();
|
|
58
|
-
var _context = /* @__PURE__ */ new WeakMap();
|
|
59
4
|
var BaseError = class _BaseError extends Error {
|
|
60
5
|
/**
|
|
61
6
|
* Primary way of defining new error classes.
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* ```ts
|
|
66
|
-
* export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
|
|
67
|
-
* ```
|
|
7
|
+
* Extended class may specialize constructor for required context params.
|
|
8
|
+
* @param code - Error code.
|
|
9
|
+
* @param message - Default error message.
|
|
68
10
|
*/
|
|
69
|
-
static extend(code) {
|
|
70
|
-
|
|
71
|
-
|
|
11
|
+
static extend(code, message) {
|
|
12
|
+
return class ExtendedError extends _BaseError {
|
|
13
|
+
static code = code;
|
|
72
14
|
static is(error) {
|
|
73
15
|
return typeof error === "object" && error !== null && "code" in error && error.code === code;
|
|
74
16
|
}
|
|
75
|
-
static wrap(
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
17
|
+
static wrap(options) {
|
|
18
|
+
const wrapFn = (error) => {
|
|
19
|
+
if (options?.ifTypeDiffers === true && this.is(error)) {
|
|
20
|
+
return error;
|
|
21
|
+
}
|
|
22
|
+
const newError = new this({
|
|
23
|
+
message,
|
|
24
|
+
...options,
|
|
25
|
+
cause: error
|
|
26
|
+
});
|
|
27
|
+
Error.captureStackTrace(newError, wrapFn);
|
|
28
|
+
return newError;
|
|
29
|
+
};
|
|
30
|
+
return wrapFn;
|
|
80
31
|
}
|
|
81
|
-
constructor(
|
|
82
|
-
super(code,
|
|
32
|
+
constructor(options) {
|
|
33
|
+
super(code, {
|
|
34
|
+
message: options?.message ?? message,
|
|
35
|
+
...options
|
|
36
|
+
});
|
|
83
37
|
}
|
|
84
|
-
}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
// NOTE: Errors go through odd transformations and the private fields seem to break.
|
|
41
|
+
code;
|
|
42
|
+
context;
|
|
43
|
+
constructor(code, options) {
|
|
44
|
+
super(options?.message, {
|
|
45
|
+
cause: options?.cause
|
|
46
|
+
});
|
|
47
|
+
this.code = code;
|
|
48
|
+
this.context = options?.context ?? {};
|
|
49
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
85
50
|
}
|
|
86
51
|
get name() {
|
|
87
|
-
return
|
|
52
|
+
return this.code;
|
|
88
53
|
}
|
|
89
|
-
|
|
90
|
-
|
|
54
|
+
/** Fallback message. */
|
|
55
|
+
get message() {
|
|
56
|
+
return this.constructor.name;
|
|
91
57
|
}
|
|
92
58
|
// For effect error matching.
|
|
93
59
|
get _tag() {
|
|
94
|
-
return
|
|
95
|
-
}
|
|
96
|
-
get context() {
|
|
97
|
-
return _class_private_field_get(this, _context);
|
|
98
|
-
}
|
|
99
|
-
constructor(code, message, options) {
|
|
100
|
-
super(message, options), _class_private_field_init(this, _code, {
|
|
101
|
-
writable: true,
|
|
102
|
-
value: void 0
|
|
103
|
-
}), _class_private_field_init(this, _context, {
|
|
104
|
-
writable: true,
|
|
105
|
-
value: void 0
|
|
106
|
-
});
|
|
107
|
-
_class_private_field_set(this, _code, code);
|
|
108
|
-
_class_private_field_set(this, _context, options?.context ?? {});
|
|
109
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
60
|
+
return this.code;
|
|
110
61
|
}
|
|
111
62
|
};
|
|
112
63
|
|
|
113
64
|
// src/errors.ts
|
|
114
|
-
var
|
|
65
|
+
var ApiError = class extends BaseError.extend("API", "API error") {
|
|
115
66
|
};
|
|
116
|
-
var
|
|
67
|
+
var SystemError = class extends BaseError.extend("SYSTEM", "System error") {
|
|
117
68
|
};
|
|
118
|
-
var
|
|
69
|
+
var InternalError = class extends BaseError.extend("INTERNAL", "Internal error") {
|
|
119
70
|
};
|
|
120
|
-
var
|
|
71
|
+
var TimeoutError = class extends BaseError.extend("TIMEOUT", "Timeout") {
|
|
121
72
|
};
|
|
122
|
-
var
|
|
73
|
+
var AbortedError = class extends BaseError.extend("ABORTED", "Aborted") {
|
|
123
74
|
};
|
|
124
|
-
var
|
|
75
|
+
var NotImplementedError = class extends BaseError.extend("NOT_IMPLEMENTED", "Not implemented") {
|
|
125
76
|
};
|
|
126
77
|
export {
|
|
127
78
|
AbortedError,
|
|
128
79
|
ApiError,
|
|
129
80
|
BaseError,
|
|
130
81
|
InternalError,
|
|
82
|
+
NotImplementedError,
|
|
131
83
|
SystemError,
|
|
132
|
-
TimeoutError
|
|
133
|
-
UnimplementedError
|
|
84
|
+
TimeoutError
|
|
134
85
|
};
|
|
135
86
|
//# 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 *
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["BaseError", "Error", "extend", "code", "is", "error", "wrap", "
|
|
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 ExtendedError 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(\n options?: Omit<BaseErrorOptions, 'cause'> & { ifTypeDiffers?: boolean },\n ): (error: unknown) => ExtendedError {\n const wrapFn = (error: unknown) => {\n if (options?.ifTypeDiffers === true && this.is(error)) {\n return error as ExtendedError;\n }\n const newError: ExtendedError = new this({ message, ...options, cause: error });\n Error.captureStackTrace(newError, wrapFn); // Position stack-trace to start from the caller of `wrap`.\n return newError;\n };\n return wrapFn;\n }\n\n constructor(options?: BaseErrorOptions) {\n super(code, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n // NOTE: Errors go through odd transformations and the private fields seem to break.\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 // For effect error matching.\n get _tag(): Code {\n return this.code;\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": ";;;AAsBO,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;EAO3D,OAAOC,OAAqCC,MAAYC,SAAkB;AACxE,WAAO,MAAMC,sBAAsBL,WAAAA;MACjC,OAAOG,OAAOA;MAEd,OAAOG,GAAGC,OAAoC;AAC5C,eAAO,OAAOA,UAAU,YAAYA,UAAU,QAAQ,UAAUA,SAASA,MAAMJ,SAASA;MAC1F;MAEA,OAAOK,KACLC,SACmC;AACnC,cAAMC,SAAS,CAACH,UAAAA;AACd,cAAIE,SAASE,kBAAkB,QAAQ,KAAKL,GAAGC,KAAAA,GAAQ;AACrD,mBAAOA;UACT;AACA,gBAAMK,WAA0B,IAAI,KAAK;YAAER;YAAS,GAAGK;YAASI,OAAON;UAAM,CAAA;AAC7EN,gBAAMa,kBAAkBF,UAAUF,MAAAA;AAClC,iBAAOE;QACT;AACA,eAAOF;MACT;MAEA,YAAYD,SAA4B;AACtC,cAAMN,MAAM;UAAEC,SAASK,SAASL,WAAWA;UAAS,GAAGK;QAAQ,CAAA;MACjE;IACF;EACF;;EAGAN;EACAY;EAEA,YAAYZ,MAAYM,SAA4B;AAClD,UAAMA,SAASL,SAAS;MAAES,OAAOJ,SAASI;IAAM,CAAA;AAEhD,SAAKV,OAAOA;AACZ,SAAKY,UAAUN,SAASM,WAAW,CAAC;AACpCC,WAAOC,eAAe,MAAM,WAAWC,SAAS;EAClD;EAEA,IAAaC,OAAO;AAClB,WAAO,KAAKhB;EACd;;EAGA,IAAaC,UAAU;AACrB,WAAO,KAAK,YAAYe;EAC1B;;EAGA,IAAIC,OAAa;AACf,WAAO,KAAKjB;EACd;AACF;;;AC5EO,IAAMkB,WAAN,cAAuBC,UAAUC,OAAO,OAAO,WAAA,EAAA;AAAc;AAE7D,IAAMC,cAAN,cAA0BF,UAAUC,OAAO,UAAU,cAAA,EAAA;AAAiB;AAEtE,IAAME,gBAAN,cAA4BH,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", "ExtendedError", "is", "error", "wrap", "options", "wrapFn", "ifTypeDiffers", "newError", "cause", "captureStackTrace", "context", "Object", "setPrototypeOf", "prototype", "name", "_tag", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/base.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/base.ts":{"bytes":7183,"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":4647},"dist/lib/node-esm/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":1594},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":491}},"bytes":2369}}}
|
package/dist/types/src/base.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Options for creating a BaseError.
|
|
3
|
+
*/
|
|
4
|
+
export type BaseErrorOptions = ErrorOptions & {
|
|
2
5
|
/**
|
|
3
|
-
*
|
|
4
|
-
* An instance of Error.
|
|
6
|
+
* Override base message.
|
|
5
7
|
*/
|
|
6
|
-
|
|
8
|
+
message?: string;
|
|
7
9
|
/**
|
|
8
10
|
* Structured details about the error.
|
|
9
11
|
*/
|
|
@@ -13,51 +15,49 @@ export type BaseErrorOptions = {
|
|
|
13
15
|
* Base class for all DXOS errors.
|
|
14
16
|
*/
|
|
15
17
|
export declare class BaseError<Code extends string = string> extends Error {
|
|
16
|
-
#private;
|
|
17
18
|
/**
|
|
18
19
|
* Primary way of defining new error classes.
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* ```ts
|
|
23
|
-
* export class AiInputPreprocessingError extends BaseError.extend('AI_INPUT_PREPROCESSING_ERROR') {}
|
|
24
|
-
* ```
|
|
20
|
+
* Extended class may specialize constructor for required context params.
|
|
21
|
+
* @param code - Error code.
|
|
22
|
+
* @param message - Default error message.
|
|
25
23
|
*/
|
|
26
|
-
static extend<Code extends string>(code: Code): {
|
|
27
|
-
new (
|
|
28
|
-
|
|
29
|
-
|
|
24
|
+
static extend<Code extends string = string>(code: Code, message?: string): {
|
|
25
|
+
new (options?: BaseErrorOptions): {
|
|
26
|
+
code: Code;
|
|
27
|
+
context: Record<string, unknown>;
|
|
30
28
|
get name(): Code;
|
|
31
|
-
|
|
29
|
+
/** Fallback message. */
|
|
30
|
+
get message(): string;
|
|
32
31
|
get _tag(): Code;
|
|
33
|
-
get context(): Record<string, unknown>;
|
|
34
|
-
message: string;
|
|
35
32
|
stack?: string;
|
|
36
33
|
cause?: unknown;
|
|
37
34
|
};
|
|
38
35
|
code: Code;
|
|
39
36
|
is(error: unknown): error is BaseError;
|
|
40
|
-
wrap(
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
wrap(options?: Omit<BaseErrorOptions, "cause"> & {
|
|
38
|
+
ifTypeDiffers?: boolean;
|
|
39
|
+
}): (error: unknown) => {
|
|
40
|
+
code: Code;
|
|
41
|
+
context: Record<string, unknown>;
|
|
43
42
|
get name(): Code;
|
|
44
|
-
|
|
43
|
+
/** Fallback message. */
|
|
44
|
+
get message(): string;
|
|
45
45
|
get _tag(): Code;
|
|
46
|
-
get context(): Record<string, unknown>;
|
|
47
|
-
message: string;
|
|
48
46
|
stack?: string;
|
|
49
47
|
cause?: unknown;
|
|
50
48
|
};
|
|
51
|
-
extend<Code extends string>(code: Code): /*elided*/ any;
|
|
49
|
+
extend<Code extends string = string>(code: Code, message?: string): /*elided*/ any;
|
|
52
50
|
isError(error: unknown): error is Error;
|
|
53
51
|
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
54
52
|
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
55
53
|
stackTraceLimit: number;
|
|
56
54
|
};
|
|
57
|
-
|
|
55
|
+
code: Code;
|
|
56
|
+
context: Record<string, unknown>;
|
|
57
|
+
constructor(code: Code, options?: BaseErrorOptions);
|
|
58
58
|
get name(): Code;
|
|
59
|
-
|
|
59
|
+
/** Fallback message. */
|
|
60
|
+
get message(): string;
|
|
60
61
|
get _tag(): Code;
|
|
61
|
-
get context(): Record<string, unknown>;
|
|
62
62
|
}
|
|
63
63
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/base.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,gBAAgB,GAAG;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/base.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG,YAAY,GAAG;IAC5C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB;;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;;;;;OAKG;IACH,MAAM,CAAC,MAAM,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM;uBAsB9C,gBAAgB;;qBAQjC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;YAchC,wBAAwB;;;;;;;kBAxCH,OAAO,GAAG,KAAK,IAAI,SAAS;uBAKjC,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,GAAG;YAAE,aAAa,CAAC,EAAE,OAAO,CAAA;SAAE,GACtE,CAAC,KAAK,EAAE,OAAO;;qBAoBb,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;;YAchC,wBAAwB;;;;;SAlCgB;eAV1B,IAAI,SAAS,MAAM,iBAAiB,IAAI,YAAY,MAAM;;;;;;IA6BxE,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAErB,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAQlD,IAAa,IAAI,SAEhB;IAED,wBAAwB;IACxB,IAAa,OAAO,WAEnB;IAGD,IAAI,IAAI,IAAI,IAAI,CAEf;CACF"}
|