@dxos/errors 0.8.4-main.406dc2a → 0.8.4-main.59c2e9b
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 +40 -96
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +40 -96
- 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 +18 -24
- package/dist/types/src/base.d.ts.map +1 -1
- package/dist/types/src/errors.d.ts +187 -180
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -2
- package/src/base.ts +27 -28
- package/src/errors.test.ts +5 -4
- package/src/errors.ts +8 -6
|
@@ -1,132 +1,75 @@
|
|
|
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
5
|
* Extended class may specialize constructor for required context params.
|
|
61
|
-
* @param
|
|
6
|
+
* @param name - Error name.
|
|
62
7
|
* @param message - Default error message.
|
|
63
8
|
*/
|
|
64
|
-
static extend(
|
|
65
|
-
|
|
66
|
-
|
|
9
|
+
static extend(name, message) {
|
|
10
|
+
return class ExtendedError extends _BaseError {
|
|
11
|
+
static name = name;
|
|
67
12
|
static is(error) {
|
|
68
|
-
return typeof error === "object" && error !== null && "
|
|
13
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === name;
|
|
69
14
|
}
|
|
70
15
|
static wrap(options) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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;
|
|
76
29
|
}
|
|
77
30
|
constructor(options) {
|
|
78
|
-
super(
|
|
31
|
+
super(name, {
|
|
79
32
|
message: options?.message ?? message,
|
|
80
33
|
...options
|
|
81
34
|
});
|
|
82
35
|
}
|
|
83
|
-
}
|
|
36
|
+
};
|
|
84
37
|
}
|
|
85
|
-
|
|
86
|
-
|
|
38
|
+
// NOTE: Errors go through odd transformations and the private fields seem to break.
|
|
39
|
+
name;
|
|
40
|
+
context;
|
|
41
|
+
constructor(name, options) {
|
|
42
|
+
super(options?.message, {
|
|
43
|
+
cause: options?.cause
|
|
44
|
+
});
|
|
45
|
+
this.name = name;
|
|
46
|
+
this.context = options?.context ?? {};
|
|
47
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
87
48
|
}
|
|
88
49
|
/** Fallback message. */
|
|
89
50
|
get message() {
|
|
90
51
|
return this.constructor.name;
|
|
91
52
|
}
|
|
92
|
-
get code() {
|
|
93
|
-
return _class_private_field_get(this, _code);
|
|
94
|
-
}
|
|
95
53
|
// For effect error matching.
|
|
96
54
|
get _tag() {
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
get context() {
|
|
100
|
-
return _class_private_field_get(this, _context);
|
|
101
|
-
}
|
|
102
|
-
constructor(code, options) {
|
|
103
|
-
super(options?.message, {
|
|
104
|
-
cause: options?.cause
|
|
105
|
-
}), _class_private_field_init(this, _code, {
|
|
106
|
-
writable: true,
|
|
107
|
-
value: void 0
|
|
108
|
-
}), _class_private_field_init(this, _context, {
|
|
109
|
-
writable: true,
|
|
110
|
-
value: void 0
|
|
111
|
-
});
|
|
112
|
-
_class_private_field_set(this, _code, code);
|
|
113
|
-
_class_private_field_set(this, _context, options?.context ?? {});
|
|
114
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
55
|
+
return this.name;
|
|
115
56
|
}
|
|
116
57
|
};
|
|
117
58
|
|
|
118
59
|
// src/errors.ts
|
|
119
|
-
var ApiError = class extends BaseError.extend("
|
|
60
|
+
var ApiError = class extends BaseError.extend("ApiError", "API error") {
|
|
61
|
+
};
|
|
62
|
+
var SystemError = class extends BaseError.extend("SystemError", "System error") {
|
|
120
63
|
};
|
|
121
|
-
var
|
|
64
|
+
var InternalError = class extends BaseError.extend("InternalError", "Internal error") {
|
|
122
65
|
};
|
|
123
|
-
var
|
|
66
|
+
var TimeoutError = class extends BaseError.extend("TimeoutError", "Timeout") {
|
|
124
67
|
};
|
|
125
|
-
var
|
|
68
|
+
var AbortedError = class extends BaseError.extend("AbortedError", "Aborted") {
|
|
126
69
|
};
|
|
127
|
-
var
|
|
70
|
+
var NotImplementedError = class extends BaseError.extend("NotImplementedError", "Not implemented") {
|
|
128
71
|
};
|
|
129
|
-
var
|
|
72
|
+
var RuntimeServiceError = class extends BaseError.extend("RuntimeServiceError", "Runtime service error") {
|
|
130
73
|
};
|
|
131
74
|
export {
|
|
132
75
|
AbortedError,
|
|
@@ -134,6 +77,7 @@ export {
|
|
|
134
77
|
BaseError,
|
|
135
78
|
InternalError,
|
|
136
79
|
NotImplementedError,
|
|
80
|
+
RuntimeServiceError,
|
|
137
81
|
SystemError,
|
|
138
82
|
TimeoutError
|
|
139
83
|
};
|
|
@@ -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\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<
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["BaseError", "Error", "extend", "
|
|
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<Name 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 name - Error name.\n * @param message - Default error message.\n */\n static extend<Name extends string = string>(name: Name, message?: string) {\n return class ExtendedError extends BaseError<Name> {\n static override name: Name = name;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'name' in error && error.name === name;\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(name, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n // NOTE: Errors go through odd transformations and the private fields seem to break.\n override name: Name;\n context: Record<string, unknown>;\n\n constructor(name: Name, options?: BaseErrorOptions) {\n super(options?.message, { cause: options?.cause });\n\n this.name = name;\n this.context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /** Fallback message. */\n override get message() {\n return this.constructor.name;\n }\n\n // For effect error matching.\n get _tag(): Name {\n return this.name;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class ApiError extends BaseError.extend('ApiError', 'API error') {}\n\nexport class SystemError extends BaseError.extend('SystemError', 'System error') {}\n\nexport class InternalError extends BaseError.extend('InternalError', 'Internal error') {}\n\nexport class TimeoutError extends BaseError.extend('TimeoutError', 'Timeout') {}\n\nexport class AbortedError extends BaseError.extend('AbortedError', 'Aborted') {}\n\nexport class NotImplementedError extends BaseError.extend('NotImplementedError', 'Not implemented') {}\n\nexport class RuntimeServiceError extends BaseError.extend('RuntimeServiceError', 'Runtime service error') {}\n"],
|
|
5
|
+
"mappings": ";AAsBO,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;EAO3D,OAAOC,OAAqCC,MAAYC,SAAkB;AACxE,WAAO,MAAMC,sBAAsBL,WAAAA;MACjC,OAAgBG,OAAaA;MAE7B,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;;EAGSN;EACTY;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;;EAGA,IAAad,UAAU;AACrB,WAAO,KAAK,YAAYD;EAC1B;;EAGA,IAAIgB,OAAa;AACf,WAAO,KAAKhB;EACd;AACF;;;ACxEO,IAAMiB,WAAN,cAAuBC,UAAUC,OAAO,YAAY,WAAA,EAAA;AAAc;AAElE,IAAMC,cAAN,cAA0BF,UAAUC,OAAO,eAAe,cAAA,EAAA;AAAiB;AAE3E,IAAME,gBAAN,cAA4BH,UAAUC,OAAO,iBAAiB,gBAAA,EAAA;AAAmB;AAEjF,IAAMG,eAAN,cAA2BJ,UAAUC,OAAO,gBAAgB,SAAA,EAAA;AAAY;AAExE,IAAMI,eAAN,cAA2BL,UAAUC,OAAO,gBAAgB,SAAA,EAAA;AAAY;AAExE,IAAMK,sBAAN,cAAkCN,UAAUC,OAAO,uBAAuB,iBAAA,EAAA;AAAoB;AAE9F,IAAMM,sBAAN,cAAkCP,UAAUC,OAAO,uBAAuB,uBAAA,EAAA;AAA0B;",
|
|
6
|
+
"names": ["BaseError", "Error", "extend", "name", "message", "ExtendedError", "is", "error", "wrap", "options", "wrapFn", "ifTypeDiffers", "newError", "cause", "captureStackTrace", "context", "Object", "setPrototypeOf", "prototype", "_tag", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError", "RuntimeServiceError"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/base.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/base.ts":{"bytes":7022,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2648,"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":4800},"dist/lib/browser/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","RuntimeServiceError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":1553},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":630}},"bytes":2397}}}
|
|
@@ -1,134 +1,77 @@
|
|
|
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
7
|
* Extended class may specialize constructor for required context params.
|
|
63
|
-
* @param
|
|
8
|
+
* @param name - Error name.
|
|
64
9
|
* @param message - Default error message.
|
|
65
10
|
*/
|
|
66
|
-
static extend(
|
|
67
|
-
|
|
68
|
-
|
|
11
|
+
static extend(name, message) {
|
|
12
|
+
return class ExtendedError extends _BaseError {
|
|
13
|
+
static name = name;
|
|
69
14
|
static is(error) {
|
|
70
|
-
return typeof error === "object" && error !== null && "
|
|
15
|
+
return typeof error === "object" && error !== null && "name" in error && error.name === name;
|
|
71
16
|
}
|
|
72
17
|
static wrap(options) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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;
|
|
78
31
|
}
|
|
79
32
|
constructor(options) {
|
|
80
|
-
super(
|
|
33
|
+
super(name, {
|
|
81
34
|
message: options?.message ?? message,
|
|
82
35
|
...options
|
|
83
36
|
});
|
|
84
37
|
}
|
|
85
|
-
}
|
|
38
|
+
};
|
|
86
39
|
}
|
|
87
|
-
|
|
88
|
-
|
|
40
|
+
// NOTE: Errors go through odd transformations and the private fields seem to break.
|
|
41
|
+
name;
|
|
42
|
+
context;
|
|
43
|
+
constructor(name, options) {
|
|
44
|
+
super(options?.message, {
|
|
45
|
+
cause: options?.cause
|
|
46
|
+
});
|
|
47
|
+
this.name = name;
|
|
48
|
+
this.context = options?.context ?? {};
|
|
49
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
89
50
|
}
|
|
90
51
|
/** Fallback message. */
|
|
91
52
|
get message() {
|
|
92
53
|
return this.constructor.name;
|
|
93
54
|
}
|
|
94
|
-
get code() {
|
|
95
|
-
return _class_private_field_get(this, _code);
|
|
96
|
-
}
|
|
97
55
|
// For effect error matching.
|
|
98
56
|
get _tag() {
|
|
99
|
-
return
|
|
100
|
-
}
|
|
101
|
-
get context() {
|
|
102
|
-
return _class_private_field_get(this, _context);
|
|
103
|
-
}
|
|
104
|
-
constructor(code, options) {
|
|
105
|
-
super(options?.message, {
|
|
106
|
-
cause: options?.cause
|
|
107
|
-
}), _class_private_field_init(this, _code, {
|
|
108
|
-
writable: true,
|
|
109
|
-
value: void 0
|
|
110
|
-
}), _class_private_field_init(this, _context, {
|
|
111
|
-
writable: true,
|
|
112
|
-
value: void 0
|
|
113
|
-
});
|
|
114
|
-
_class_private_field_set(this, _code, code);
|
|
115
|
-
_class_private_field_set(this, _context, options?.context ?? {});
|
|
116
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
57
|
+
return this.name;
|
|
117
58
|
}
|
|
118
59
|
};
|
|
119
60
|
|
|
120
61
|
// src/errors.ts
|
|
121
|
-
var ApiError = class extends BaseError.extend("
|
|
62
|
+
var ApiError = class extends BaseError.extend("ApiError", "API error") {
|
|
63
|
+
};
|
|
64
|
+
var SystemError = class extends BaseError.extend("SystemError", "System error") {
|
|
122
65
|
};
|
|
123
|
-
var
|
|
66
|
+
var InternalError = class extends BaseError.extend("InternalError", "Internal error") {
|
|
124
67
|
};
|
|
125
|
-
var
|
|
68
|
+
var TimeoutError = class extends BaseError.extend("TimeoutError", "Timeout") {
|
|
126
69
|
};
|
|
127
|
-
var
|
|
70
|
+
var AbortedError = class extends BaseError.extend("AbortedError", "Aborted") {
|
|
128
71
|
};
|
|
129
|
-
var
|
|
72
|
+
var NotImplementedError = class extends BaseError.extend("NotImplementedError", "Not implemented") {
|
|
130
73
|
};
|
|
131
|
-
var
|
|
74
|
+
var RuntimeServiceError = class extends BaseError.extend("RuntimeServiceError", "Runtime service error") {
|
|
132
75
|
};
|
|
133
76
|
export {
|
|
134
77
|
AbortedError,
|
|
@@ -136,6 +79,7 @@ export {
|
|
|
136
79
|
BaseError,
|
|
137
80
|
InternalError,
|
|
138
81
|
NotImplementedError,
|
|
82
|
+
RuntimeServiceError,
|
|
139
83
|
SystemError,
|
|
140
84
|
TimeoutError
|
|
141
85
|
};
|
|
@@ -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\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<
|
|
5
|
-
"mappings": ";;;
|
|
6
|
-
"names": ["BaseError", "Error", "extend", "
|
|
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<Name 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 name - Error name.\n * @param message - Default error message.\n */\n static extend<Name extends string = string>(name: Name, message?: string) {\n return class ExtendedError extends BaseError<Name> {\n static override name: Name = name;\n\n static is(error: unknown): error is BaseError {\n return typeof error === 'object' && error !== null && 'name' in error && error.name === name;\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(name, { message: options?.message ?? message, ...options });\n }\n };\n }\n\n // NOTE: Errors go through odd transformations and the private fields seem to break.\n override name: Name;\n context: Record<string, unknown>;\n\n constructor(name: Name, options?: BaseErrorOptions) {\n super(options?.message, { cause: options?.cause });\n\n this.name = name;\n this.context = options?.context ?? {};\n Object.setPrototypeOf(this, new.target.prototype);\n }\n\n /** Fallback message. */\n override get message() {\n return this.constructor.name;\n }\n\n // For effect error matching.\n get _tag(): Name {\n return this.name;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { BaseError } from './base';\n\nexport class ApiError extends BaseError.extend('ApiError', 'API error') {}\n\nexport class SystemError extends BaseError.extend('SystemError', 'System error') {}\n\nexport class InternalError extends BaseError.extend('InternalError', 'Internal error') {}\n\nexport class TimeoutError extends BaseError.extend('TimeoutError', 'Timeout') {}\n\nexport class AbortedError extends BaseError.extend('AbortedError', 'Aborted') {}\n\nexport class NotImplementedError extends BaseError.extend('NotImplementedError', 'Not implemented') {}\n\nexport class RuntimeServiceError extends BaseError.extend('RuntimeServiceError', 'Runtime service error') {}\n"],
|
|
5
|
+
"mappings": ";;;AAsBO,IAAMA,YAAN,MAAMA,mBAAgDC,MAAAA;;;;;;;EAO3D,OAAOC,OAAqCC,MAAYC,SAAkB;AACxE,WAAO,MAAMC,sBAAsBL,WAAAA;MACjC,OAAgBG,OAAaA;MAE7B,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;;EAGSN;EACTY;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;;EAGA,IAAad,UAAU;AACrB,WAAO,KAAK,YAAYD;EAC1B;;EAGA,IAAIgB,OAAa;AACf,WAAO,KAAKhB;EACd;AACF;;;ACxEO,IAAMiB,WAAN,cAAuBC,UAAUC,OAAO,YAAY,WAAA,EAAA;AAAc;AAElE,IAAMC,cAAN,cAA0BF,UAAUC,OAAO,eAAe,cAAA,EAAA;AAAiB;AAE3E,IAAME,gBAAN,cAA4BH,UAAUC,OAAO,iBAAiB,gBAAA,EAAA;AAAmB;AAEjF,IAAMG,eAAN,cAA2BJ,UAAUC,OAAO,gBAAgB,SAAA,EAAA;AAAY;AAExE,IAAMI,eAAN,cAA2BL,UAAUC,OAAO,gBAAgB,SAAA,EAAA;AAAY;AAExE,IAAMK,sBAAN,cAAkCN,UAAUC,OAAO,uBAAuB,iBAAA,EAAA;AAAoB;AAE9F,IAAMM,sBAAN,cAAkCP,UAAUC,OAAO,uBAAuB,uBAAA,EAAA;AAA0B;",
|
|
6
|
+
"names": ["BaseError", "Error", "extend", "name", "message", "ExtendedError", "is", "error", "wrap", "options", "wrapFn", "ifTypeDiffers", "newError", "cause", "captureStackTrace", "context", "Object", "setPrototypeOf", "prototype", "_tag", "ApiError", "BaseError", "extend", "SystemError", "InternalError", "TimeoutError", "AbortedError", "NotImplementedError", "RuntimeServiceError"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/base.ts":{"bytes":
|
|
1
|
+
{"inputs":{"src/base.ts":{"bytes":7022,"imports":[],"format":"esm"},"src/errors.ts":{"bytes":2648,"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":4802},"dist/lib/node-esm/index.mjs":{"imports":[],"exports":["AbortedError","ApiError","BaseError","InternalError","NotImplementedError","RuntimeServiceError","SystemError","TimeoutError"],"entryPoint":"src/index.ts","inputs":{"src/base.ts":{"bytesInOutput":1553},"src/index.ts":{"bytesInOutput":0},"src/errors.ts":{"bytesInOutput":630}},"bytes":2490}}}
|
package/dist/types/src/base.d.ts
CHANGED
|
@@ -14,53 +14,47 @@ export type BaseErrorOptions = ErrorOptions & {
|
|
|
14
14
|
/**
|
|
15
15
|
* Base class for all DXOS errors.
|
|
16
16
|
*/
|
|
17
|
-
export declare class BaseError<
|
|
18
|
-
#private;
|
|
17
|
+
export declare class BaseError<Name extends string = string> extends Error {
|
|
19
18
|
/**
|
|
20
19
|
* Primary way of defining new error classes.
|
|
21
20
|
* Extended class may specialize constructor for required context params.
|
|
22
|
-
* @param
|
|
21
|
+
* @param name - Error name.
|
|
23
22
|
* @param message - Default error message.
|
|
24
23
|
*/
|
|
25
|
-
static extend<
|
|
24
|
+
static extend<Name extends string = string>(name: Name, message?: string): {
|
|
26
25
|
new (options?: BaseErrorOptions): {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
get name(): Code;
|
|
26
|
+
name: Name;
|
|
27
|
+
context: Record<string, unknown>;
|
|
30
28
|
/** Fallback message. */
|
|
31
29
|
get message(): string;
|
|
32
|
-
get
|
|
33
|
-
get _tag(): Code;
|
|
34
|
-
get context(): Record<string, unknown>;
|
|
30
|
+
get _tag(): Name;
|
|
35
31
|
stack?: string;
|
|
36
32
|
cause?: unknown;
|
|
37
33
|
};
|
|
38
|
-
|
|
34
|
+
name: Name;
|
|
39
35
|
is(error: unknown): error is BaseError;
|
|
40
|
-
wrap(options?: Omit<BaseErrorOptions, "cause">
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
wrap(options?: Omit<BaseErrorOptions, "cause"> & {
|
|
37
|
+
ifTypeDiffers?: boolean;
|
|
38
|
+
}): (error: unknown) => {
|
|
39
|
+
name: Name;
|
|
40
|
+
context: Record<string, unknown>;
|
|
44
41
|
/** Fallback message. */
|
|
45
42
|
get message(): string;
|
|
46
|
-
get
|
|
47
|
-
get _tag(): Code;
|
|
48
|
-
get context(): Record<string, unknown>;
|
|
43
|
+
get _tag(): Name;
|
|
49
44
|
stack?: string;
|
|
50
45
|
cause?: unknown;
|
|
51
46
|
};
|
|
52
|
-
extend<
|
|
47
|
+
extend<Name extends string = string>(name: Name, message?: string): /*elided*/ any;
|
|
53
48
|
isError(error: unknown): error is Error;
|
|
54
49
|
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
55
50
|
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
56
51
|
stackTraceLimit: number;
|
|
57
52
|
};
|
|
58
|
-
|
|
59
|
-
|
|
53
|
+
name: Name;
|
|
54
|
+
context: Record<string, unknown>;
|
|
55
|
+
constructor(name: Name, options?: BaseErrorOptions);
|
|
60
56
|
/** Fallback message. */
|
|
61
57
|
get message(): string;
|
|
62
|
-
get
|
|
63
|
-
get _tag(): Code;
|
|
64
|
-
get context(): Record<string, unknown>;
|
|
58
|
+
get _tag(): Name;
|
|
65
59
|
}
|
|
66
60
|
//# sourceMappingURL=base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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
|
|
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;YAUhC,wBAAwB;;;;;;cAtCE,IAAI;kBAET,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;YAUhC,wBAAwB;;;;;SA9BgB;eAV1B,IAAI,SAAS,MAAM,iBAAiB,IAAI,YAAY,MAAM;;;;;;IA6B/D,IAAI,EAAE,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAErB,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,gBAAgB;IAQlD,wBAAwB;IACxB,IAAa,OAAO,WAEnB;IAGD,IAAI,IAAI,IAAI,IAAI,CAEf;CACF"}
|