@idlebox/errors 0.1.17 → 0.1.18
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/lib/autoindex.d.ts +27 -23
- package/lib/autoindex.d.ts.map +1 -1
- package/lib/autoindex.js +41 -25
- package/lib/autoindex.js.map +1 -1
- package/lib/common/base.d.ts +5 -49
- package/lib/common/base.d.ts.map +1 -1
- package/lib/common/base.js +10 -62
- package/lib/common/base.js.map +1 -1
- package/lib/common/human-readable.d.ts +6 -0
- package/lib/common/human-readable.d.ts.map +1 -0
- package/lib/common/human-readable.js +5 -0
- package/lib/common/human-readable.js.map +1 -0
- package/lib/common/not-error.d.ts +12 -0
- package/lib/common/not-error.d.ts.map +1 -0
- package/lib/common/not-error.js +20 -0
- package/lib/common/not-error.js.map +1 -0
- package/lib/common/type-shim.d.ts +5 -0
- package/lib/common/type-shim.d.ts.map +1 -0
- package/lib/common/type-shim.js +3 -0
- package/lib/common/type-shim.js.map +1 -0
- package/lib/common/type.d.ts +13 -0
- package/lib/common/type.d.ts.map +1 -0
- package/lib/common/type.js +2 -0
- package/lib/common/type.js.map +1 -0
- package/lib/common/v8.d.ts +3 -0
- package/lib/common/v8.d.ts.map +1 -0
- package/lib/common/v8.js +4 -0
- package/lib/common/v8.js.map +1 -0
- package/lib/{common → error-types}/application.d.ts +4 -1
- package/lib/error-types/application.d.ts.map +1 -0
- package/lib/{common → error-types}/application.js +3 -1
- package/lib/error-types/application.js.map +1 -0
- package/lib/error-types/dependency.d.ts +24 -0
- package/lib/error-types/dependency.d.ts.map +1 -0
- package/lib/error-types/dependency.js +39 -0
- package/lib/error-types/dependency.js.map +1 -0
- package/lib/error-types/development.d.ts +27 -0
- package/lib/error-types/development.d.ts.map +1 -0
- package/lib/error-types/development.js +50 -0
- package/lib/error-types/development.js.map +1 -0
- package/lib/error-types/nodejs.d.ts.map +1 -0
- package/lib/error-types/nodejs.js.map +1 -0
- package/lib/{common/unhandled-errors.d.ts → error-types/nodejs.unhandled.d.ts} +1 -1
- package/lib/error-types/nodejs.unhandled.d.ts.map +1 -0
- package/lib/{common/unhandled-errors.js → error-types/nodejs.unhandled.js} +1 -1
- package/lib/error-types/nodejs.unhandled.js.map +1 -0
- package/lib/error-types/tools.d.ts +28 -0
- package/lib/error-types/tools.d.ts.map +1 -0
- package/lib/error-types/tools.js +41 -0
- package/lib/error-types/tools.js.map +1 -0
- package/package.json +2 -2
- package/src/autoindex.ts +46 -30
- package/src/common/base.ts +11 -90
- package/src/common/human-readable.ts +8 -0
- package/src/common/not-error.ts +19 -0
- package/src/common/type-shim.ts +7 -0
- package/src/common/type.ts +13 -0
- package/src/common/v8.ts +4 -0
- package/src/{common → error-types}/application.ts +4 -1
- package/src/error-types/dependency.ts +51 -0
- package/src/error-types/development.ts +61 -0
- package/src/error-types/tools.ts +48 -0
- package/lib/common/application.d.ts.map +0 -1
- package/lib/common/application.js.map +0 -1
- package/lib/common/development.d.ts +0 -12
- package/lib/common/development.d.ts.map +0 -1
- package/lib/common/development.js +0 -24
- package/lib/common/development.js.map +0 -1
- package/lib/common/nodejs.d.ts.map +0 -1
- package/lib/common/nodejs.js.map +0 -1
- package/lib/common/unhandled-errors.d.ts.map +0 -1
- package/lib/common/unhandled-errors.js.map +0 -1
- package/src/common/development.ts +0 -24
- /package/lib/{common → error-types}/nodejs.d.ts +0 -0
- /package/lib/{common → error-types}/nodejs.js +0 -0
- /package/src/{common → error-types}/nodejs.ts +0 -0
- /package/src/{common/unhandled-errors.ts → error-types/nodejs.unhandled.ts} +0 -0
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ExitCode } from '../codes/wellknown-exit-codes.js';
|
|
2
|
+
import { ErrorWithCode } from '../common/base.js';
|
|
3
|
+
/**
|
|
4
|
+
* 由于程序出现bug导致的各类异常
|
|
5
|
+
*/
|
|
6
|
+
export class ProgramError extends ErrorWithCode {
|
|
7
|
+
constructor(message, opts) {
|
|
8
|
+
super(message, ExitCode.PROGRAM, opts);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class NotImplementedError extends ProgramError {
|
|
12
|
+
constructor(message = '此功能未实现', opts) {
|
|
13
|
+
super(message, opts);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export class SoftwareDefectError extends ProgramError {
|
|
17
|
+
}
|
|
18
|
+
export class Assertion extends SoftwareDefectError {
|
|
19
|
+
static ok(value, message = '断言失败', opts) {
|
|
20
|
+
if (!value) {
|
|
21
|
+
if (!opts?.boundary) {
|
|
22
|
+
if (!opts)
|
|
23
|
+
opts = {};
|
|
24
|
+
opts.boundary = Assertion.ok;
|
|
25
|
+
}
|
|
26
|
+
throw new SoftwareDefectError(`${message}: 应为真值, 实际为${typeof value}类型的 "${value}"`, opts);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export class VariableTypeError extends ProgramError {
|
|
31
|
+
object;
|
|
32
|
+
ExpectedClass;
|
|
33
|
+
constructor(object, { Expected, variableName = '变量', ...opts } = {}) {
|
|
34
|
+
let message = '';
|
|
35
|
+
if (Expected) {
|
|
36
|
+
message += `应是 ${Expected.name}`;
|
|
37
|
+
}
|
|
38
|
+
const Actual = object.constructor;
|
|
39
|
+
if (message) {
|
|
40
|
+
message += ', 实际是 ';
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
message += '不能是 ';
|
|
44
|
+
}
|
|
45
|
+
message += Actual.name;
|
|
46
|
+
super(`${object}的类型${message}`, opts);
|
|
47
|
+
this.object = object;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"development.js","sourceRoot":"","sources":["../../src/error-types/development.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGlD;;GAEG;AACH,M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|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodejs.unhandled.d.ts","sourceRoot":"","sources":["../../src/error-types/nodejs.unhandled.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAM,YAAa,SAAQ,KAAK;IACvB,KAAK,EAAE,GAAG,CAAC;gBAEP,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO;IAK7C,IAAa,KAAK,IAAI,MAAM,CAS3B;CACD;AAED,qBAAa,kBAAmB,SAAQ,YAAY;aAGlC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;gBADzC,MAAM,EAAE,OAAO,EACC,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC;CAI1C;AAED,qBAAa,iBAAkB,SAAQ,YAAY;aACtB,KAAK,EAAE,KAAK;gBAAZ,KAAK,EAAE,KAAK;CAGxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nodejs.unhandled.js","sourceRoot":"","sources":["../../src/error-types/nodejs.unhandled.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,YAAa,SAAQ,KAAK;IAG/B,YAAY,MAAc,EAAE,QAAiB;QAC5C,KAAK,CAAC,GAAG,MAAM,KAAK,WAAW,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClE,OAAQ,IAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED,IAAa,KAAK;QACjB,MAAM,KAAK,GAAQ,IAAI,CAAC,KAAK,CAAC;QAC9B,IAAI,KAAK,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;YAC/B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAC1B,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC/B,OAAO,GAAG,IAAI,CAAC,OAAO,KAAK,eAAe,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3D,CAAC;QACF,CAAC;QACD,OAAO,GAAG,IAAI,CAAC,OAAO,wBAAwB,CAAC;IAChD,CAAC;CACD;AAED,MAAM,OAAO,kBAAmB,SAAQ,YAAY;IAGlC;IAFjB,YACC,MAAe,EACC,OAAyB;QAEzC,KAAK,CAAC,6BAA6B,EAAE,MAAM,CAAC,CAAC;QAF7B,YAAO,GAAP,OAAO,CAAkB;IAG1C,CAAC;CACD;AAED,MAAM,OAAO,iBAAkB,SAAQ,YAAY;IACtB;IAA5B,YAA4B,KAAY;QACvC,KAAK,CAAC,oBAAoB,EAAE,KAAK,CAAC,CAAC;QADR,UAAK,GAAL,KAAK,CAAO;IAExC,CAAC;CACD;AAED,SAAS,WAAW,CAAC,MAAW;IAC/B,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;QAC7B,OAAO,MAAM,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,SAAS,IAAI,MAAM,EAAE,CAAC;QACjE,OAAO,MAAM,CAAC,OAAO,CAAC;IACvB,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,eAAe,CAAC,IAAY;IACpC,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,IAAI,KAAK,KAAK,CAAC,CAAC,EAAE,CAAC;QAClB,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;IAC9B,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { ErrorWithCode } from '../common/base.js';
|
|
2
|
+
import { humanReadable, type IHumanReadable } from '../common/human-readable.js';
|
|
3
|
+
import type { IErrorOptions } from '../common/type.js';
|
|
4
|
+
/**
|
|
5
|
+
* 发生本程序主动发起的取消行为时
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare class CanceledError extends ErrorWithCode implements IHumanReadable {
|
|
9
|
+
constructor(opts?: IErrorOptions);
|
|
10
|
+
static is(e: unknown): e is CanceledError;
|
|
11
|
+
[humanReadable](): string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* 某种操作超时
|
|
15
|
+
*
|
|
16
|
+
* @public
|
|
17
|
+
*/
|
|
18
|
+
export declare class TimeoutError extends ErrorWithCode implements IHumanReadable {
|
|
19
|
+
private readonly ms;
|
|
20
|
+
private readonly why;
|
|
21
|
+
private readonly what?;
|
|
22
|
+
constructor(ms: number, why?: string, opts?: IErrorOptions & {
|
|
23
|
+
what?: string;
|
|
24
|
+
});
|
|
25
|
+
static is(error: unknown): error is TimeoutError;
|
|
26
|
+
[humanReadable](): string;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../src/error-types/tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;;GAGG;AACH,qBAAa,aAAc,SAAQ,aAAc,YAAW,cAAc;gBAC7D,IAAI,CAAC,EAAE,aAAa;IAIhC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,aAAa;IAIhC,CAAC,aAAa,CAAC;CAGxB;AAED;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,aAAc,YAAW,cAAc;IAIvE,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,GAAG;IAJrB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAS;gBAGb,EAAE,EAAE,MAAM,EACV,GAAG,SAAgB,EACpC,IAAI,CAAC,EAAE,aAAa,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE;IAMzC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY;IAIvC,CAAC,aAAa,CAAC;CAGxB"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ExitCode } from '../codes/wellknown-exit-codes.js';
|
|
2
|
+
import { ErrorWithCode } from '../common/base.js';
|
|
3
|
+
import { humanReadable } from '../common/human-readable.js';
|
|
4
|
+
/**
|
|
5
|
+
* 发生本程序主动发起的取消行为时
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export class CanceledError extends ErrorWithCode {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
super('Canceled', ExitCode.INTERRUPT, opts);
|
|
11
|
+
}
|
|
12
|
+
static is(e) {
|
|
13
|
+
return e instanceof CanceledError;
|
|
14
|
+
}
|
|
15
|
+
[humanReadable]() {
|
|
16
|
+
return '操作已应要求而取消';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 某种操作超时
|
|
21
|
+
*
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
export class TimeoutError extends ErrorWithCode {
|
|
25
|
+
ms;
|
|
26
|
+
why;
|
|
27
|
+
what;
|
|
28
|
+
constructor(ms, why = 'no response', opts) {
|
|
29
|
+
super(`Timeout: ${why} in ${ms}ms${opts?.what ? ` (when ${opts.what})` : ''}`, ExitCode.TIMEOUT, opts);
|
|
30
|
+
this.ms = ms;
|
|
31
|
+
this.why = why;
|
|
32
|
+
this.what = opts?.what;
|
|
33
|
+
}
|
|
34
|
+
static is(error) {
|
|
35
|
+
return error instanceof TimeoutError;
|
|
36
|
+
}
|
|
37
|
+
[humanReadable]() {
|
|
38
|
+
return `操作超时: ${this.what ? this.what : '操作没有说明'}\n - 时长: ${this.ms}ms\n - 原因: ${this.why}`;
|
|
39
|
+
}
|
|
40
|
+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AAI,CAAC,CAAC,CAAC,QAAQ,aAAa,IAAI,CAAC,EAAE,eAAe,IAAI,CAAC,GAAG,EAAE,CAAC;IAC/F,CAAC;CACD"}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@idlebox/errors",
|
|
3
3
|
"description": "A collection of my errors.",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.18",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"source": "./src/autoindex.ts",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@build-script/baseline-rig": "latest",
|
|
19
|
-
"@mpis/run": "^0.0.
|
|
19
|
+
"@mpis/run": "^0.0.25"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "GongT <admin@gongt.me>",
|
package/src/autoindex.ts
CHANGED
|
@@ -22,37 +22,53 @@
|
|
|
22
22
|
/* codes/wellknown-exit-codes.ts */
|
|
23
23
|
// Identifiers (1)
|
|
24
24
|
export { ExitCode } from "./codes/wellknown-exit-codes.js";
|
|
25
|
-
/* common/application.ts */
|
|
26
|
-
// Identifiers (3)
|
|
27
|
-
export { Exit } from "./common/application.js";
|
|
28
|
-
export { InterruptError } from "./common/application.js";
|
|
29
|
-
export { UsageError } from "./common/application.js";
|
|
30
25
|
/* common/base.ts */
|
|
31
|
-
// Identifiers (
|
|
32
|
-
export type { IErrorOptions } from "./common/base.js";
|
|
33
|
-
export { humanReadable } from "./common/base.js";
|
|
34
|
-
export type { IHumanReadable } from "./common/base.js";
|
|
35
|
-
export { isHumanReadableError } from "./common/base.js";
|
|
36
|
-
export { NotError } from "./common/base.js";
|
|
26
|
+
// Identifiers (2)
|
|
37
27
|
export { ErrorWithCode } from "./common/base.js";
|
|
38
|
-
export {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
export {
|
|
43
|
-
export {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
28
|
+
export { TypeErrorWithCode } from "./common/base.js";
|
|
29
|
+
/* common/human-readable.ts */
|
|
30
|
+
// Identifiers (3)
|
|
31
|
+
export { humanReadable } from "./common/human-readable.js";
|
|
32
|
+
export type { IHumanReadable } from "./common/human-readable.js";
|
|
33
|
+
export { isHumanReadable } from "./common/human-readable.js";
|
|
34
|
+
/* common/not-error.ts */
|
|
35
|
+
// Identifiers (1)
|
|
36
|
+
export { NotError } from "./common/not-error.js";
|
|
37
|
+
/* common/type.ts */
|
|
38
|
+
// Identifiers (1)
|
|
39
|
+
export type { IErrorOptions } from "./common/type.js";
|
|
40
|
+
/* common/v8.ts */
|
|
41
|
+
// Identifiers (0)
|
|
42
|
+
/* error-types/application.ts */
|
|
43
|
+
// Identifiers (3)
|
|
44
|
+
export { Exit } from "./error-types/application.js";
|
|
45
|
+
export { InterruptError } from "./error-types/application.js";
|
|
46
|
+
export { UsageError } from "./error-types/application.js";
|
|
47
|
+
/* error-types/dependency.ts */
|
|
48
|
+
// Identifiers (2)
|
|
49
|
+
export { DependencyError } from "./error-types/dependency.js";
|
|
50
|
+
export { ChildProcessExitError } from "./error-types/dependency.js";
|
|
51
|
+
/* error-types/development.ts */
|
|
52
|
+
// Identifiers (5)
|
|
53
|
+
export { ProgramError } from "./error-types/development.js";
|
|
54
|
+
export { NotImplementedError } from "./error-types/development.js";
|
|
55
|
+
export { SoftwareDefectError } from "./error-types/development.js";
|
|
56
|
+
export { Assertion } from "./error-types/development.js";
|
|
57
|
+
export { VariableTypeError } from "./error-types/development.js";
|
|
58
|
+
/* error-types/nodejs.ts */
|
|
47
59
|
// Identifiers (7)
|
|
48
|
-
export type { OpenSSLException } from "./
|
|
49
|
-
export { isModuleResolutionError } from "./
|
|
50
|
-
export { isNotExistsError } from "./
|
|
51
|
-
export { isExistsError } from "./
|
|
52
|
-
export { isTypeError } from "./
|
|
53
|
-
export { isFileTypeError } from "./
|
|
54
|
-
export { isNodeError } from "./
|
|
55
|
-
/*
|
|
60
|
+
export type { OpenSSLException } from "./error-types/nodejs.js";
|
|
61
|
+
export { isModuleResolutionError } from "./error-types/nodejs.js";
|
|
62
|
+
export { isNotExistsError } from "./error-types/nodejs.js";
|
|
63
|
+
export { isExistsError } from "./error-types/nodejs.js";
|
|
64
|
+
export { isTypeError } from "./error-types/nodejs.js";
|
|
65
|
+
export { isFileTypeError } from "./error-types/nodejs.js";
|
|
66
|
+
export { isNodeError } from "./error-types/nodejs.js";
|
|
67
|
+
/* error-types/nodejs.unhandled.ts */
|
|
68
|
+
// Identifiers (2)
|
|
69
|
+
export { UnhandledRejection } from "./error-types/nodejs.unhandled.js";
|
|
70
|
+
export { UncaughtException } from "./error-types/nodejs.unhandled.js";
|
|
71
|
+
/* error-types/tools.ts */
|
|
56
72
|
// Identifiers (2)
|
|
57
|
-
export {
|
|
58
|
-
export {
|
|
73
|
+
export { CanceledError } from "./error-types/tools.js";
|
|
74
|
+
export { TimeoutError } from "./error-types/tools.js";
|
package/src/common/base.ts
CHANGED
|
@@ -1,51 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const replaceStackTrace = Error.captureStackTrace ?? noop;
|
|
6
|
-
|
|
7
|
-
export interface IErrorOptions {
|
|
8
|
-
/**
|
|
9
|
-
* stack属性的边界函数
|
|
10
|
-
* @see {Error.captureStackTrace}
|
|
11
|
-
*/
|
|
12
|
-
boundary?: CallableFunction;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* cause属性的值
|
|
16
|
-
* @see {Error.cause}
|
|
17
|
-
*/
|
|
18
|
-
cause?: unknown;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const humanReadable = Symbol('humanReadable');
|
|
22
|
-
export interface IHumanReadable {
|
|
23
|
-
[humanReadable](): string;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function isHumanReadableError(error: unknown): error is IHumanReadable {
|
|
27
|
-
return error instanceof Object && humanReadable in error;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* 利用try...catch统一接口,或是用于分支条件等,未发生错误的情况
|
|
32
|
-
*/
|
|
33
|
-
export class NotError implements IHumanReadable {
|
|
34
|
-
constructor(public readonly extra_message: string = '') {}
|
|
35
|
-
|
|
36
|
-
get stack() {
|
|
37
|
-
throw new Error(`NotError 未被正确捕获 [hint: ${this.extra_message}]`);
|
|
38
|
-
}
|
|
39
|
-
get message() {
|
|
40
|
-
throw new Error(`NotError 未被正确捕获 [hint: ${this.extra_message}]`);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
[humanReadable]() {
|
|
44
|
-
return `你不应该看到此消息。你无需尝试处理该错误,请联系开发者。[hint: ${this.extra_message}]`;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
1
|
+
import { humanReadable, type IHumanReadable } from './human-readable.js';
|
|
2
|
+
import type { IErrorOptions } from './type.js';
|
|
3
|
+
import { captureStackTrace } from './v8.js';
|
|
47
4
|
|
|
48
5
|
/**
|
|
6
|
+
* 最基本的错误类型
|
|
7
|
+
* 其他所有错误的基类
|
|
49
8
|
* @abstract
|
|
50
9
|
*/
|
|
51
10
|
export class ErrorWithCode extends Error implements IHumanReadable {
|
|
@@ -56,7 +15,7 @@ export class ErrorWithCode extends Error implements IHumanReadable {
|
|
|
56
15
|
) {
|
|
57
16
|
super(message, opts);
|
|
58
17
|
|
|
59
|
-
|
|
18
|
+
captureStackTrace(this, opts?.boundary ?? this.constructor);
|
|
60
19
|
}
|
|
61
20
|
|
|
62
21
|
public override get name() {
|
|
@@ -66,55 +25,17 @@ export class ErrorWithCode extends Error implements IHumanReadable {
|
|
|
66
25
|
[humanReadable]() {
|
|
67
26
|
let msg: string;
|
|
68
27
|
if (this.code === 0) {
|
|
69
|
-
msg = '
|
|
28
|
+
msg = '未发生异常';
|
|
70
29
|
} else {
|
|
71
|
-
msg =
|
|
30
|
+
msg = `异常状态 [${this.code}]`;
|
|
72
31
|
}
|
|
73
32
|
return `${msg}\n - 但是你不应该看到此信息,开发者忘记处理此种情况`;
|
|
74
33
|
}
|
|
75
34
|
}
|
|
76
35
|
|
|
77
|
-
|
|
36
|
+
export class TypeErrorWithCode extends ErrorWithCode {}
|
|
78
37
|
|
|
79
38
|
/**
|
|
80
|
-
*
|
|
81
|
-
* @public
|
|
39
|
+
* 假装继承自 TypeError
|
|
82
40
|
*/
|
|
83
|
-
|
|
84
|
-
constructor(opts?: IErrorOptions) {
|
|
85
|
-
super('Canceled', ExitCode.INTERRUPT, opts);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
static is(e: unknown): e is CanceledError {
|
|
89
|
-
return e instanceof CanceledError;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
override [humanReadable]() {
|
|
93
|
-
return '操作已应用户要求而取消';
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Error when something timeout
|
|
99
|
-
* @public
|
|
100
|
-
*/
|
|
101
|
-
export class TimeoutError extends ErrorWithCode implements IHumanReadable {
|
|
102
|
-
private readonly what?: string;
|
|
103
|
-
|
|
104
|
-
constructor(
|
|
105
|
-
private readonly ms: number,
|
|
106
|
-
private readonly why = 'no response',
|
|
107
|
-
opts?: IErrorOptions & { what?: string },
|
|
108
|
-
) {
|
|
109
|
-
super(`Timeout: ${why} in ${ms}ms${opts?.what ? ` (when ${opts.what})` : ''}`, ExitCode.TIMEOUT, opts);
|
|
110
|
-
this.what = opts?.what;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
static is(error: unknown): error is TimeoutError {
|
|
114
|
-
return error instanceof TimeoutError;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
override [humanReadable]() {
|
|
118
|
-
return `操作超时: ${this.what ? this.what : '操作没有说明'}\n - 时长: ${this.ms}ms\n - 原因: ${this.why}`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
41
|
+
Object.setPrototypeOf(TypeErrorWithCode.prototype, TypeError.prototype);
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { humanReadable, type IHumanReadable } from './human-readable.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 利用try...catch统一接口,或是用于分支条件等,未发生错误的情况
|
|
5
|
+
*/
|
|
6
|
+
export class NotError implements IHumanReadable {
|
|
7
|
+
constructor(public readonly extra_message: string = '') {}
|
|
8
|
+
|
|
9
|
+
get stack() {
|
|
10
|
+
throw new Error(`NotError 未被正确捕获 [hint: ${this.extra_message}]`);
|
|
11
|
+
}
|
|
12
|
+
get message() {
|
|
13
|
+
throw new Error(`NotError 未被正确捕获 [hint: ${this.extra_message}]`);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
[humanReadable]() {
|
|
17
|
+
return `你不应该看到此消息。你无需尝试处理该错误,请联系开发者。[hint: ${this.extra_message}]`;
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/common/v8.ts
ADDED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { ExitCode } from '../codes/wellknown-exit-codes.js';
|
|
2
|
-
import { ErrorWithCode
|
|
2
|
+
import { ErrorWithCode } from '../common/base.js';
|
|
3
|
+
import { humanReadable } from '../common/human-readable.js';
|
|
4
|
+
import type { IErrorOptions } from '../common/type.js';
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* 程序因为正常运行结束而退出
|
|
@@ -30,6 +32,7 @@ export class InterruptError extends ErrorWithCode {
|
|
|
30
32
|
|
|
31
33
|
/**
|
|
32
34
|
* 由于错误的参数、配置导致错误
|
|
35
|
+
* 非程序问题
|
|
33
36
|
*/
|
|
34
37
|
export class UsageError extends ErrorWithCode {
|
|
35
38
|
constructor(message: string, opts?: IErrorOptions) {
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { ChildProcess, SignalsType } from '../common/type-shim.js';
|
|
2
|
+
import type { IErrorOptions } from '../common/type.js';
|
|
3
|
+
import { ProgramError } from './development.js';
|
|
4
|
+
|
|
5
|
+
export class DependencyError extends ProgramError {}
|
|
6
|
+
|
|
7
|
+
interface IChildProcessErrorOptions extends IErrorOptions {
|
|
8
|
+
readonly commandline?: readonly string[];
|
|
9
|
+
readonly pid?: number;
|
|
10
|
+
readonly workingDirectory?: string;
|
|
11
|
+
readonly exitCode?: number;
|
|
12
|
+
readonly signal?: SignalsType;
|
|
13
|
+
readonly process?: ChildProcess;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class ChildProcessExitError extends DependencyError {
|
|
17
|
+
public pid?: number;
|
|
18
|
+
public commandline?: readonly string[];
|
|
19
|
+
public workingDirectory?: string;
|
|
20
|
+
public exitCode?: number;
|
|
21
|
+
public signal?: SignalsType;
|
|
22
|
+
public process?: ChildProcess;
|
|
23
|
+
|
|
24
|
+
constructor({ pid, commandline, workingDirectory, exitCode, signal, process, ...opts }: IChildProcessErrorOptions) {
|
|
25
|
+
let message = '';
|
|
26
|
+
message += pid ? `子进程 ${pid} ` : '未知子进程';
|
|
27
|
+
message += '非预期退出, ';
|
|
28
|
+
if (exitCode) {
|
|
29
|
+
message += `返回 ${exitCode}`;
|
|
30
|
+
} else if (signal) {
|
|
31
|
+
message += `信号 ${signal}`;
|
|
32
|
+
} else {
|
|
33
|
+
message += '可能未正常启动';
|
|
34
|
+
}
|
|
35
|
+
if (commandline) {
|
|
36
|
+
message += `\n 命令行: ${commandline.join(' ')}`;
|
|
37
|
+
}
|
|
38
|
+
if (workingDirectory) {
|
|
39
|
+
message += `\n 工作目录: ${workingDirectory}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
super(message, opts);
|
|
43
|
+
|
|
44
|
+
this.pid = pid;
|
|
45
|
+
this.commandline = commandline;
|
|
46
|
+
this.workingDirectory = workingDirectory;
|
|
47
|
+
this.exitCode = exitCode;
|
|
48
|
+
this.signal = signal;
|
|
49
|
+
this.process = process;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { ExitCode } from '../codes/wellknown-exit-codes.js';
|
|
2
|
+
import { ErrorWithCode } from '../common/base.js';
|
|
3
|
+
import type { IErrorOptions } from '../common/type.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 由于程序出现bug导致的各类异常
|
|
7
|
+
*/
|
|
8
|
+
export abstract class ProgramError extends ErrorWithCode {
|
|
9
|
+
constructor(message: string, opts?: IErrorOptions) {
|
|
10
|
+
super(message, ExitCode.PROGRAM, opts);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class NotImplementedError extends ProgramError {
|
|
15
|
+
constructor(message: string = '此功能未实现', opts?: IErrorOptions) {
|
|
16
|
+
super(message, opts);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export class SoftwareDefectError extends ProgramError {}
|
|
21
|
+
|
|
22
|
+
export class Assertion extends SoftwareDefectError {
|
|
23
|
+
static ok(value: unknown, message: string = '断言失败', opts?: IErrorOptions): asserts value {
|
|
24
|
+
if (!value) {
|
|
25
|
+
if (!opts?.boundary) {
|
|
26
|
+
if (!opts) opts = {};
|
|
27
|
+
opts.boundary = Assertion.ok;
|
|
28
|
+
}
|
|
29
|
+
throw new SoftwareDefectError(`${message}: 应为真值, 实际为${typeof value}类型的 "${value}"`, opts);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface IVariableTypeErrorOptions extends IErrorOptions {
|
|
35
|
+
Expected?: Function;
|
|
36
|
+
variableName?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class VariableTypeError extends ProgramError {
|
|
40
|
+
public readonly ExpectedClass?: Function;
|
|
41
|
+
|
|
42
|
+
constructor(
|
|
43
|
+
public readonly object: any,
|
|
44
|
+
{ Expected, variableName = '变量', ...opts }: IVariableTypeErrorOptions = {},
|
|
45
|
+
) {
|
|
46
|
+
let message = '';
|
|
47
|
+
if (Expected) {
|
|
48
|
+
message += `应是 ${Expected.name}`;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const Actual = object.constructor;
|
|
52
|
+
if (message) {
|
|
53
|
+
message += ', 实际是 ';
|
|
54
|
+
} else {
|
|
55
|
+
message += '不能是 ';
|
|
56
|
+
}
|
|
57
|
+
message += Actual.name;
|
|
58
|
+
|
|
59
|
+
super(`${object}的类型${message}`, opts);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ExitCode } from '../codes/wellknown-exit-codes.js';
|
|
2
|
+
import { ErrorWithCode } from '../common/base.js';
|
|
3
|
+
import { humanReadable, type IHumanReadable } from '../common/human-readable.js';
|
|
4
|
+
import type { IErrorOptions } from '../common/type.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 发生本程序主动发起的取消行为时
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export class CanceledError extends ErrorWithCode implements IHumanReadable {
|
|
11
|
+
constructor(opts?: IErrorOptions) {
|
|
12
|
+
super('Canceled', ExitCode.INTERRUPT, opts);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static is(e: unknown): e is CanceledError {
|
|
16
|
+
return e instanceof CanceledError;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
override [humanReadable]() {
|
|
20
|
+
return '操作已应要求而取消';
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 某种操作超时
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
*/
|
|
29
|
+
export class TimeoutError extends ErrorWithCode implements IHumanReadable {
|
|
30
|
+
private readonly what?: string;
|
|
31
|
+
|
|
32
|
+
constructor(
|
|
33
|
+
private readonly ms: number,
|
|
34
|
+
private readonly why = 'no response',
|
|
35
|
+
opts?: IErrorOptions & { what?: string },
|
|
36
|
+
) {
|
|
37
|
+
super(`Timeout: ${why} in ${ms}ms${opts?.what ? ` (when ${opts.what})` : ''}`, ExitCode.TIMEOUT, opts);
|
|
38
|
+
this.what = opts?.what;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static is(error: unknown): error is TimeoutError {
|
|
42
|
+
return error instanceof TimeoutError;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
override [humanReadable]() {
|
|
46
|
+
return `操作超时: ${this.what ? this.what : '操作没有说明'}\n - 时长: ${this.ms}ms\n - 原因: ${this.why}`;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application.d.ts","sourceRoot":"","sources":["../../src/common/application.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE7E;;;GAGG;AACH,qBAAa,IAAK,SAAQ,aAAa;gBAC1B,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa;CAG9C;AAED;;;GAGG;AACH,qBAAa,cAAe,SAAQ,aAAa;aAE/B,MAAM,EAAE,MAAM,CAAC,OAAO;gBAAtB,MAAM,EAAE,MAAM,CAAC,OAAO,EACtC,IAAI,CAAC,EAAE,aAAa;IAKZ,CAAC,aAAa,CAAC;CAGxB;AAED;;GAEG;AACH,qBAAa,UAAW,SAAQ,aAAa;gBAChC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa;IAIxC,CAAC,aAAa,CAAC;CAGxB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application.js","sourceRoot":"","sources":["../../src/common/application.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,aAAa,EAAsB,MAAM,WAAW,CAAC;AAE7E;;;GAGG;AACH,MAAM,OAAO,IAAK,SAAQ,aAAa;IACtC,YAAY,IAAY,EAAE,IAAoB;QAC7C,KAAK,CAAC,0BAA0B,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IACrD,CAAC;CACD;AAED;;;GAGG;AACH,MAAM,OAAO,cAAe,SAAQ,aAAa;IAE/B;IADjB,YACiB,MAAsB,EACtC,IAAoB;QAEpB,KAAK,CAAC,uBAAuB,MAAM,EAAE,EAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;QAHjD,WAAM,GAAN,MAAM,CAAgB;IAIvC,CAAC;IAEQ,CAAC,aAAa,CAAC;QACvB,OAAO,SAAS,IAAI,CAAC,MAAM,OAAO,CAAC;IACpC,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IAC5C,YAAY,OAAe,EAAE,IAAoB;QAChD,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACtC,CAAC;IAEQ,CAAC,aAAa,CAAC;QACvB,OAAO,SAAS,IAAI,CAAC,OAAO,+BAA+B,CAAC;IAC7D,CAAC;CACD"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ErrorWithCode, type IErrorOptions } from './base.js';
|
|
2
|
-
export declare abstract class ProgramError extends ErrorWithCode {
|
|
3
|
-
constructor(message: string, opts?: IErrorOptions);
|
|
4
|
-
}
|
|
5
|
-
export declare class NotImplementedError extends ProgramError {
|
|
6
|
-
}
|
|
7
|
-
export declare class SoftwareDefectError extends ProgramError {
|
|
8
|
-
}
|
|
9
|
-
export declare class Assertion extends SoftwareDefectError {
|
|
10
|
-
static ok(value: unknown, message?: string, opts?: IErrorOptions): asserts value;
|
|
11
|
-
}
|
|
12
|
-
//# sourceMappingURL=development.d.ts.map
|