@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,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
+ }
@@ -1,7 +1,4 @@
1
- /**
2
- *
3
- */
4
- class ProxiedError extends Error {
1
+ export abstract class ProxiedError extends Error {
5
2
  declare cause: any;
6
3
 
7
4
  constructor(prefix: string, original: unknown) {
@@ -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
@@ -1 +0,0 @@
1
- {"version":3,"file":"development.d.ts","sourceRoot":"","sources":["../../src/common/development.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,KAAK,aAAa,EAAE,MAAM,WAAW,CAAC;AAE9D,8BAAsB,YAAa,SAAQ,aAAa;gBAC3C,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,aAAa;CAGjD;AAED,qBAAa,mBAAoB,SAAQ,YAAY;CAAG;AAExD,qBAAa,mBAAoB,SAAQ,YAAY;CAAG;AAExD,qBAAa,SAAU,SAAQ,mBAAmB;IACjD,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,GAAE,MAA2B,EAAE,IAAI,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,KAAK;CASpG"}
@@ -1,24 +0,0 @@
1
- import { ExitCode } from '../codes/wellknown-exit-codes.js';
2
- import { ErrorWithCode } from './base.js';
3
- export class ProgramError extends ErrorWithCode {
4
- constructor(message, opts) {
5
- super(message, ExitCode.PROGRAM, opts);
6
- }
7
- }
8
- export class NotImplementedError extends ProgramError {
9
- }
10
- export class SoftwareDefectError extends ProgramError {
11
- }
12
- export class Assertion extends SoftwareDefectError {
13
- static ok(value, message = 'Assertion failed', opts) {
14
- if (!value) {
15
- if (!opts?.boundary) {
16
- if (!opts)
17
- opts = {};
18
- opts.boundary = Assertion.ok;
19
- }
20
- throw new SoftwareDefectError(`${message}: value should be truthy, got ${typeof value} (${value})`, opts);
21
- }
22
- }
23
- }
24
- //# sourceMappingURL=development.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"development.js","sourceRoot":"","sources":["../../src/common/development.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5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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 +0,0 @@
1
- {"version":3,"file":"unhandled-errors.d.ts","sourceRoot":"","sources":["../../src/common/unhandled-errors.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"}
@@ -1,24 +0,0 @@
1
- import { ExitCode } from '../codes/wellknown-exit-codes.js';
2
- import { ErrorWithCode, type IErrorOptions } from './base.js';
3
-
4
- export abstract class ProgramError extends ErrorWithCode {
5
- constructor(message: string, opts?: IErrorOptions) {
6
- super(message, ExitCode.PROGRAM, opts);
7
- }
8
- }
9
-
10
- export class NotImplementedError extends ProgramError {}
11
-
12
- export class SoftwareDefectError extends ProgramError {}
13
-
14
- export class Assertion extends SoftwareDefectError {
15
- static ok(value: unknown, message: string = 'Assertion failed', opts?: IErrorOptions): asserts value {
16
- if (!value) {
17
- if (!opts?.boundary) {
18
- if (!opts) opts = {};
19
- opts.boundary = Assertion.ok;
20
- }
21
- throw new SoftwareDefectError(`${message}: value should be truthy, got ${typeof value} (${value})`, opts);
22
- }
23
- }
24
- }
File without changes
File without changes
File without changes