@idlebox/errors 0.1.5
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/LICENSE +21 -0
- package/lib/autoindex.d.ts +21 -0
- package/lib/autoindex.d.ts.map +1 -0
- package/lib/autoindex.js +37 -0
- package/lib/autoindex.js.map +1 -0
- package/lib/codes/linux-error-codes.d.ts +125 -0
- package/lib/codes/linux-error-codes.d.ts.map +1 -0
- package/lib/codes/linux-error-codes.js +126 -0
- package/lib/codes/linux-error-codes.js.map +1 -0
- package/lib/codes/nodejs-re-export.d.ts +2 -0
- package/lib/codes/nodejs-re-export.d.ts.map +1 -0
- package/lib/codes/nodejs-re-export.js +2 -0
- package/lib/codes/nodejs-re-export.js.map +1 -0
- package/lib/codes/wellknown-exit-codes.d.ts +19 -0
- package/lib/codes/wellknown-exit-codes.d.ts.map +1 -0
- package/lib/codes/wellknown-exit-codes.js +20 -0
- package/lib/codes/wellknown-exit-codes.js.map +1 -0
- package/lib/common/application.d.ts +23 -0
- package/lib/common/application.d.ts.map +1 -0
- package/lib/common/application.js +31 -0
- package/lib/common/application.js.map +1 -0
- package/lib/common/base.d.ts +10 -0
- package/lib/common/base.d.ts.map +1 -0
- package/lib/common/base.js +20 -0
- package/lib/common/base.js.map +1 -0
- package/lib/common/development.d.ts +11 -0
- package/lib/common/development.d.ts.map +1 -0
- package/lib/common/development.js +20 -0
- package/lib/common/development.js.map +1 -0
- package/lib/common/nodejs.d.ts +30 -0
- package/lib/common/nodejs.d.ts.map +1 -0
- package/lib/common/nodejs.js +30 -0
- package/lib/common/nodejs.js.map +1 -0
- package/lib/common/unhandled-errors.d.ts +18 -0
- package/lib/common/unhandled-errors.d.ts.map +1 -0
- package/lib/common/unhandled-errors.js +50 -0
- package/lib/common/unhandled-errors.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +33 -0
- package/src/autoindex.ts +40 -0
- package/src/codes/linux-error-codes.ts +124 -0
- package/src/codes/nodejs-re-export.ts +1 -0
- package/src/codes/wellknown-exit-codes.ts +21 -0
- package/src/common/application.ts +34 -0
- package/src/common/base.ts +25 -0
- package/src/common/development.ts +22 -0
- package/src/common/nodejs.ts +44 -0
- package/src/common/unhandled-errors.ts +55 -0
- package/src/tsconfig.json +12 -0
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
*/
|
|
4
|
+
class ProxiedError extends Error {
|
|
5
|
+
declare cause: any;
|
|
6
|
+
|
|
7
|
+
constructor(prefix: string, original: unknown) {
|
|
8
|
+
super(`${prefix}: ${get_message(original)}`, { cause: original });
|
|
9
|
+
delete (this as any).stack;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
override get stack(): string {
|
|
13
|
+
const cause: any = this.cause;
|
|
14
|
+
if (cause && 'stack' in cause) {
|
|
15
|
+
const stack = cause.stack;
|
|
16
|
+
if (typeof stack === 'string') {
|
|
17
|
+
return this.message + '\n' + removeFirstLine(cause.stack);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return `${this.message}\n no stack available`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export class UnhandledRejection extends ProxiedError {
|
|
25
|
+
constructor(
|
|
26
|
+
reason: unknown,
|
|
27
|
+
public readonly promise: Promise<unknown>,
|
|
28
|
+
) {
|
|
29
|
+
super('unhandled promise rejection', reason);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class UncaughtException extends ProxiedError {
|
|
34
|
+
constructor(public readonly error: Error) {
|
|
35
|
+
super('uncaught exception', error);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function get_message(reason: any): string {
|
|
40
|
+
if (reason instanceof Error) {
|
|
41
|
+
return reason.message;
|
|
42
|
+
}
|
|
43
|
+
if (reason && typeof reason === 'object' && 'message' in reason) {
|
|
44
|
+
return reason.message;
|
|
45
|
+
}
|
|
46
|
+
return String(reason);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function removeFirstLine(text: string) {
|
|
50
|
+
const index = text.indexOf('\n');
|
|
51
|
+
if (index !== -1) {
|
|
52
|
+
return text.slice(index + 1);
|
|
53
|
+
}
|
|
54
|
+
return text;
|
|
55
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "@internal/local-rig/profiles/default/tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"typeRoots": ["../node_modules/@types", "../node_modules"],
|
|
5
|
+
"outDir": "../lib",
|
|
6
|
+
"rootDir": "./",
|
|
7
|
+
"types": ["node"]
|
|
8
|
+
},
|
|
9
|
+
// "files": ["preload.ts"],
|
|
10
|
+
// "include": ["**/*.ts"],
|
|
11
|
+
"exclude": ["**/*.generator.ts"]
|
|
12
|
+
}
|