@idlebox/errors 0.1.17 → 0.1.19

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.
Files changed (81) hide show
  1. package/lib/autoindex.d.ts +28 -23
  2. package/lib/autoindex.d.ts.map +1 -1
  3. package/lib/autoindex.js +42 -25
  4. package/lib/autoindex.js.map +1 -1
  5. package/lib/codes/wellknown-exit-codes.d.ts +19 -2
  6. package/lib/codes/wellknown-exit-codes.d.ts.map +1 -1
  7. package/lib/codes/wellknown-exit-codes.js +18 -1
  8. package/lib/codes/wellknown-exit-codes.js.map +1 -1
  9. package/lib/common/base.d.ts +5 -49
  10. package/lib/common/base.d.ts.map +1 -1
  11. package/lib/common/base.js +10 -62
  12. package/lib/common/base.js.map +1 -1
  13. package/lib/common/human-readable.d.ts +6 -0
  14. package/lib/common/human-readable.d.ts.map +1 -0
  15. package/lib/common/human-readable.js +5 -0
  16. package/lib/common/human-readable.js.map +1 -0
  17. package/lib/common/not-error.d.ts +12 -0
  18. package/lib/common/not-error.d.ts.map +1 -0
  19. package/lib/common/not-error.js +20 -0
  20. package/lib/common/not-error.js.map +1 -0
  21. package/lib/common/type-shim.d.ts +5 -0
  22. package/lib/common/type-shim.d.ts.map +1 -0
  23. package/lib/common/type-shim.js +3 -0
  24. package/lib/common/type-shim.js.map +1 -0
  25. package/lib/common/type.d.ts +13 -0
  26. package/lib/common/type.d.ts.map +1 -0
  27. package/lib/common/type.js +2 -0
  28. package/lib/common/type.js.map +1 -0
  29. package/lib/common/v8.d.ts +3 -0
  30. package/lib/common/v8.d.ts.map +1 -0
  31. package/lib/common/v8.js +4 -0
  32. package/lib/common/v8.js.map +1 -0
  33. package/lib/{common → error-types}/application.d.ts +4 -1
  34. package/lib/error-types/application.d.ts.map +1 -0
  35. package/lib/{common → error-types}/application.js +3 -1
  36. package/lib/error-types/application.js.map +1 -0
  37. package/lib/error-types/dependency.d.ts +24 -0
  38. package/lib/error-types/dependency.d.ts.map +1 -0
  39. package/lib/error-types/dependency.js +39 -0
  40. package/lib/error-types/dependency.js.map +1 -0
  41. package/lib/error-types/development.d.ts +27 -0
  42. package/lib/error-types/development.d.ts.map +1 -0
  43. package/lib/error-types/development.js +50 -0
  44. package/lib/error-types/development.js.map +1 -0
  45. package/lib/error-types/nodejs.d.ts.map +1 -0
  46. package/lib/error-types/nodejs.js.map +1 -0
  47. package/lib/{common/unhandled-errors.d.ts → error-types/nodejs.unhandled.d.ts} +2 -6
  48. package/lib/error-types/nodejs.unhandled.d.ts.map +1 -0
  49. package/lib/{common/unhandled-errors.js → error-types/nodejs.unhandled.js} +2 -5
  50. package/lib/{common/unhandled-errors.js.map → error-types/nodejs.unhandled.js.map} +1 -1
  51. package/lib/error-types/tools.d.ts +28 -0
  52. package/lib/error-types/tools.d.ts.map +1 -0
  53. package/lib/error-types/tools.js +41 -0
  54. package/lib/error-types/tools.js.map +1 -0
  55. package/package.json +2 -2
  56. package/src/autoindex.ts +47 -30
  57. package/src/codes/wellknown-exit-codes.ts +22 -1
  58. package/src/common/base.ts +11 -90
  59. package/src/common/human-readable.ts +8 -0
  60. package/src/common/not-error.ts +19 -0
  61. package/src/common/type-shim.ts +7 -0
  62. package/src/common/type.ts +13 -0
  63. package/src/common/v8.ts +4 -0
  64. package/src/{common → error-types}/application.ts +4 -1
  65. package/src/error-types/dependency.ts +51 -0
  66. package/src/error-types/development.ts +61 -0
  67. package/src/{common/unhandled-errors.ts → error-types/nodejs.unhandled.ts} +1 -4
  68. package/src/error-types/tools.ts +48 -0
  69. package/lib/common/application.d.ts.map +0 -1
  70. package/lib/common/application.js.map +0 -1
  71. package/lib/common/development.d.ts +0 -12
  72. package/lib/common/development.d.ts.map +0 -1
  73. package/lib/common/development.js +0 -24
  74. package/lib/common/development.js.map +0 -1
  75. package/lib/common/nodejs.d.ts.map +0 -1
  76. package/lib/common/nodejs.js.map +0 -1
  77. package/lib/common/unhandled-errors.d.ts.map +0 -1
  78. package/src/common/development.ts +0 -24
  79. /package/lib/{common → error-types}/nodejs.d.ts +0 -0
  80. /package/lib/{common → error-types}/nodejs.js +0 -0
  81. /package/src/{common → error-types}/nodejs.ts +0 -0
@@ -0,0 +1,39 @@
1
+ import { ProgramError } from './development.js';
2
+ export class DependencyError extends ProgramError {
3
+ }
4
+ export class ChildProcessExitError extends DependencyError {
5
+ pid;
6
+ commandline;
7
+ workingDirectory;
8
+ exitCode;
9
+ signal;
10
+ process;
11
+ constructor({ pid, commandline, workingDirectory, exitCode, signal, process, ...opts }) {
12
+ let message = '';
13
+ message += pid ? `子进程 ${pid} ` : '未知子进程';
14
+ message += '非预期退出, ';
15
+ if (exitCode) {
16
+ message += `返回 ${exitCode}`;
17
+ }
18
+ else if (signal) {
19
+ message += `信号 ${signal}`;
20
+ }
21
+ else {
22
+ message += '可能未正常启动';
23
+ }
24
+ if (commandline) {
25
+ message += `\n 命令行: ${commandline.join(' ')}`;
26
+ }
27
+ if (workingDirectory) {
28
+ message += `\n 工作目录: ${workingDirectory}`;
29
+ }
30
+ super(message, opts);
31
+ this.pid = pid;
32
+ this.commandline = commandline;
33
+ this.workingDirectory = workingDirectory;
34
+ this.exitCode = exitCode;
35
+ this.signal = signal;
36
+ this.process = process;
37
+ }
38
+ }
39
+ //# sourceMappingURL=dependency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency.js","sourceRoot":"","sources":["../../src/error-types/dependency.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,MAAM,OAAO,eAAgB,SAAQ,YAAY;CAAG;AAWpD,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IAClD,GAAG,CAAU;IACb,WAAW,CAAqB;IAChC,gBAAgB,CAAU;IAC1B,QAAQ,CAAU;IAClB,MAAM,CAAe;IACrB,OAAO,CAAgB;IAE9B,YAAY,EAAE,GAAG,EAAE,WAAW,EAAE,gBAAgB,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,EAA6B;QAChH,IAAI,OAAO,GAAG,EAAE,CAAC;QACjB,OAAO,IAAI,GAAG,CAAC,CAAC,CAAC,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC;QACzC,OAAO,IAAI,SAAS,CAAC;QACrB,IAAI,QAAQ,EAAE,CAAC;YACd,OAAO,IAAI,MAAM,QAAQ,EAAE,CAAC;QAC7B,CAAC;aAAM,IAAI,MAAM,EAAE,CAAC;YACnB,OAAO,IAAI,MAAM,MAAM,EAAE,CAAC;QAC3B,CAAC;aAAM,CAAC;YACP,OAAO,IAAI,SAAS,CAAC;QACtB,CAAC;QACD,IAAI,WAAW,EAAE,CAAC;YACjB,OAAO,IAAI,YAAY,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAChD,CAAC;QACD,IAAI,gBAAgB,EAAE,CAAC;YACtB,OAAO,IAAI,aAAa,gBAAgB,EAAE,CAAC;QAC5C,CAAC;QAED,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAErB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAC/B,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD"}
@@ -0,0 +1,27 @@
1
+ import { ErrorWithCode } from '../common/base.js';
2
+ import type { IErrorOptions } from '../common/type.js';
3
+ /**
4
+ * 由于程序出现bug导致的各类异常
5
+ */
6
+ export declare abstract class ProgramError extends ErrorWithCode {
7
+ constructor(message: string, opts?: IErrorOptions);
8
+ }
9
+ export declare class NotImplementedError extends ProgramError {
10
+ constructor(message?: string, opts?: IErrorOptions);
11
+ }
12
+ export declare class SoftwareDefectError extends ProgramError {
13
+ }
14
+ export declare class Assertion extends SoftwareDefectError {
15
+ static ok(value: unknown, message?: string, opts?: IErrorOptions): asserts value;
16
+ }
17
+ interface IVariableTypeErrorOptions extends IErrorOptions {
18
+ Expected?: Function;
19
+ variableName?: string;
20
+ }
21
+ export declare class VariableTypeError extends ProgramError {
22
+ readonly object: any;
23
+ readonly ExpectedClass?: Function;
24
+ constructor(object: any, { Expected, variableName, ...opts }?: IVariableTypeErrorOptions);
25
+ }
26
+ export {};
27
+ //# sourceMappingURL=development.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"development.d.ts","sourceRoot":"","sources":["../../src/error-types/development.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD;;GAEG;AACH,8BAAsB,YAAa,SAAQ,aAAa;gBAC3C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa;CAGjD;AAED,qBAAa,mBAAoB,SAAQ,YAAY;gBACxC,OAAO,GAAE,MAAiB,EAAE,IAAI,CAAC,EAAE,aAAa;CAG5D;AAED,qBAAa,mBAAoB,SAAQ,YAAY;CAAG;AAExD,qBAAa,SAAU,SAAQ,mBAAmB;IACjD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,MAAe,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK;CASxF;AAED,UAAU,yBAA0B,SAAQ,aAAa;IACxD,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,iBAAkB,SAAQ,YAAY;aAIjC,MAAM,EAAE,GAAG;IAH5B,SAAgB,aAAa,CAAC,EAAE,QAAQ,CAAC;gBAGxB,MAAM,EAAE,GAAG,EAC3B,EAAE,QAAQ,EAAE,YAAmB,EAAE,GAAG,IAAI,EAAE,GAAE,yBAA8B;CAiB3E"}
@@ -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,MAAM,OAAgB,YAAa,SAAQ,aAAa;IACvD,YAAY,OAAe,EAAE,IAAoB;QAChD,KAAK,CAAC,OAAO,EAAE,QAAQ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}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodejs.js","sourceRoot":"","sources":["../../src/error-types/nodejs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAW/D;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,EAAW;IAClD,OAAO,WAAW,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,aAAa,CAAC,gBAAgB,IAAI,EAAE,CAAC,IAAI,KAAK,aAAa,CAAC,oBAAoB,CAAC,CAAC;AAC1H,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,CAAU;IAC1C,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,MAAM,CAAC;AAC3D,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,CAAU;IACvC,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,MAAM,CAAC;AAC3D,CAAC;AAED,uCAAuC;AACvC,MAAM,CAAC,MAAM,WAAW,GAAG,eAAe,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,CAAU;IACzC,OAAO,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,MAAM,IAAI,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,CAAC,CAAC;AAClG,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,CAAU;IACrC,OAAO,CAAC,YAAY,KAAK,IAAI,OAAQ,CAAS,CAAC,IAAI,KAAK,QAAQ,CAAC;AAClE,CAAC"}
@@ -1,7 +1,4 @@
1
- /**
2
- *
3
- */
4
- declare class ProxiedError extends Error {
1
+ export declare abstract class ProxiedError extends Error {
5
2
  cause: any;
6
3
  constructor(prefix: string, original: unknown);
7
4
  get stack(): string;
@@ -14,5 +11,4 @@ export declare class UncaughtException extends ProxiedError {
14
11
  readonly error: Error;
15
12
  constructor(error: Error);
16
13
  }
17
- export {};
18
- //# sourceMappingURL=unhandled-errors.d.ts.map
14
+ //# sourceMappingURL=nodejs.unhandled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodejs.unhandled.d.ts","sourceRoot":"","sources":["../../src/error-types/nodejs.unhandled.ts"],"names":[],"mappings":"AAAA,8BAAsB,YAAa,SAAQ,KAAK;IACvC,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"}
@@ -1,7 +1,4 @@
1
- /**
2
- *
3
- */
4
- class ProxiedError extends Error {
1
+ export class ProxiedError extends Error {
5
2
  constructor(prefix, original) {
6
3
  super(`${prefix}: ${get_message(original)}`, { cause: original });
7
4
  delete this.stack;
@@ -47,4 +44,4 @@ function removeFirstLine(text) {
47
44
  }
48
45
  return text;
49
46
  }
50
- //# sourceMappingURL=unhandled-errors.js.map
47
+ //# sourceMappingURL=nodejs.unhandled.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"unhandled-errors.js","sourceRoot":"","sources":["../../src/common/unhandled-errors.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,E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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
+ }
41
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../src/error-types/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAuB,MAAM,6BAA6B,CAAC;AAGjF;;;GAGG;AACH,MAAM,OAAO,aAAc,SAAQ,aAAa;IAC/C,YAAY,IAAoB;QAC/B,KAAK,CAAC,UAAU,EAAE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,CAAU;QACnB,OAAO,CAAC,YAAY,aAAa,CAAC;IACnC,CAAC;IAEQ,CAAC,aAAa,CAAC;QACvB,OAAO,WAAW,CAAC;IACpB,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,OAAO,YAAa,SAAQ,aAAa;IAI5B;IACA;IAJD,IAAI,CAAU;IAE/B,YACkB,EAAU,EACV,MAAM,aAAa,EACpC,IAAwC;QAExC,KAAK,CAAC,YAAY,GAAG,OAAO,EAAE,KAAK,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAJtF,OAAE,GAAF,EAAE,CAAQ;QACV,QAAG,GAAH,GAAG,CAAgB;QAIpC,IAAI,CAAC,IAAI,GAAG,IAAI,EAAE,IAAI,CAAC;IACxB,CAAC;IAED,MAAM,CAAC,EAAE,CAAC,KAAc;QACvB,OAAO,KAAK,YAAY,YAAY,CAAC;IACtC,CAAC;IAEQ,CAAC,aAAa,CAAC;QACvB,OAAO,SAAS,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,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.17",
5
+ "version": "0.1.19",
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.21"
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,54 @@
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 (8)
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 { CanceledError } from "./common/base.js";
39
- export { TimeoutError } from "./common/base.js";
40
- /* common/development.ts */
41
- // Identifiers (4)
42
- export { ProgramError } from "./common/development.js";
43
- export { NotImplementedError } from "./common/development.js";
44
- export { SoftwareDefectError } from "./common/development.js";
45
- export { Assertion } from "./common/development.js";
46
- /* common/nodejs.ts */
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 "./common/nodejs.js";
49
- export { isModuleResolutionError } from "./common/nodejs.js";
50
- export { isNotExistsError } from "./common/nodejs.js";
51
- export { isExistsError } from "./common/nodejs.js";
52
- export { isTypeError } from "./common/nodejs.js";
53
- export { isFileTypeError } from "./common/nodejs.js";
54
- export { isNodeError } from "./common/nodejs.js";
55
- /* common/unhandled-errors.ts */
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 (3)
69
+ export { ProxiedError } from "./error-types/nodejs.unhandled.js";
70
+ export { UnhandledRejection } from "./error-types/nodejs.unhandled.js";
71
+ export { UncaughtException } from "./error-types/nodejs.unhandled.js";
72
+ /* error-types/tools.ts */
56
73
  // Identifiers (2)
57
- export { UnhandledRejection } from "./common/unhandled-errors.js";
58
- export { UncaughtException } from "./common/unhandled-errors.js";
74
+ export { CanceledError } from "./error-types/tools.js";
75
+ export { TimeoutError } from "./error-types/tools.js";
@@ -20,7 +20,28 @@ export enum ExitCode {
20
20
  TIMEOUT = 4,
21
21
 
22
22
  /**
23
- * 由于程序代码不完善导致的错误
23
+ * 工作状态异常
24
+ * 状态转移错误等
25
+ */
26
+ INVALID_STATE = 5,
27
+
28
+ /**
29
+ * 由于程序代码不完善导致的未知错误
24
30
  */
25
31
  PROGRAM = 66,
32
+
33
+ /**
34
+ * 由资源引起的错误,例如文件不存在、网络错误等
35
+ */
36
+ RESOURCE = 100,
37
+
38
+ /**
39
+ * 重复操作,例如重复调用dispose
40
+ */
41
+ DUPLICATE = 101,
42
+
43
+ /**
44
+ * 未曾设想的错误
45
+ */
46
+ UNKNOWN = 233,
26
47
  }
@@ -1,51 +1,10 @@
1
- import { ExitCode } from '../codes/wellknown-exit-codes.js';
2
-
3
- function noop() {}
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
- replaceStackTrace(this, opts?.boundary ?? this.constructor);
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 = `程序以非0状态正常结束,状态码:${this.code}`;
30
+ msg = `异常状态 [${this.code}]`;
72
31
  }
73
32
  return `${msg}\n - 但是你不应该看到此信息,开发者忘记处理此种情况`;
74
33
  }
75
34
  }
76
35
 
77
- Object.setPrototypeOf(ErrorWithCode.prototype, Error.prototype);
36
+ export class TypeErrorWithCode extends ErrorWithCode {}
78
37
 
79
38
  /**
80
- * Error when something.cancel() is called
81
- * @public
39
+ * 假装继承自 TypeError
82
40
  */
83
- export class CanceledError extends ErrorWithCode implements IHumanReadable {
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,8 @@
1
+ export const humanReadable = Symbol('humanReadable');
2
+ export interface IHumanReadable {
3
+ [humanReadable](): string;
4
+ }
5
+
6
+ export function isHumanReadable(error: unknown): error is IHumanReadable {
7
+ return error instanceof Object && humanReadable in error;
8
+ }
@@ -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
+ }
@@ -0,0 +1,7 @@
1
+ // biome-ignore-all lint/suspicious/noTsIgnore: 切换文件
2
+
3
+ /** @ts-ignore */
4
+ export type ChildProcess = import('node:child_process').ChildProcess;
5
+
6
+ /** @ts-ignore */
7
+ export type SignalsType = NodeJS.Signals;
@@ -0,0 +1,13 @@
1
+ export interface IErrorOptions {
2
+ /**
3
+ * stack属性的边界函数
4
+ * @see {Error.captureStackTrace}
5
+ */
6
+ boundary?: CallableFunction;
7
+
8
+ /**
9
+ * cause属性的值
10
+ * @see {Error.cause}
11
+ */
12
+ cause?: unknown;
13
+ }
@@ -0,0 +1,4 @@
1
+ function noop() {}
2
+
3
+ /** @internal */
4
+ export const captureStackTrace = Error.captureStackTrace ?? noop;
@@ -1,5 +1,7 @@
1
1
  import { ExitCode } from '../codes/wellknown-exit-codes.js';
2
- import { ErrorWithCode, humanReadable, type IErrorOptions } from './base.js';
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) {