kerium 1.3.4 → 1.3.6
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/error.d.ts +1 -1
- package/dist/error.js +5 -10
- package/dist/log.js +10 -18
- package/package.json +1 -1
package/dist/error.d.ts
CHANGED
|
@@ -454,7 +454,7 @@ export declare class Exception extends Error implements NodeJS.ErrnoException, E
|
|
|
454
454
|
export declare function UV(this: void, code: keyof typeof Errno, syscall: string, path?: string, dest?: string): Exception;
|
|
455
455
|
export declare function UV(this: void, code: keyof typeof Errno, context?: ExceptionExtra): Exception;
|
|
456
456
|
/**
|
|
457
|
-
* Shortcut to easily create an `
|
|
457
|
+
* Shortcut to easily create an `Exception` with a specific error code.
|
|
458
458
|
*/
|
|
459
459
|
export declare function withErrno(this: void, code: keyof typeof Errno, message?: string): Exception;
|
|
460
460
|
export declare function rethrow(syscall: string, path?: string, dest?: string): (e: Exception) => never;
|
package/dist/error.js
CHANGED
|
@@ -415,7 +415,7 @@ export function setUVMessage(ex) {
|
|
|
415
415
|
message += ` '${ex.path}'`;
|
|
416
416
|
if (ex.dest)
|
|
417
417
|
message += ` -> '${ex.dest}'`;
|
|
418
|
-
if (ex.message && ex.message
|
|
418
|
+
if (ex.message && !ex.message.startsWith(errnoMessages[ex.errno]))
|
|
419
419
|
message += ` (${ex.message})`;
|
|
420
420
|
ex.message = message;
|
|
421
421
|
return ex;
|
|
@@ -439,17 +439,12 @@ export class Exception extends Error {
|
|
|
439
439
|
syscall;
|
|
440
440
|
constructor(errno, message, ctx = {}) {
|
|
441
441
|
const code = Errno[errno];
|
|
442
|
-
|
|
443
|
-
message = `${code}: ${errnoMessages[errno]}, ${ctx.syscall}`;
|
|
444
|
-
if (ctx.path)
|
|
445
|
-
message += ` '${ctx.path}'`;
|
|
446
|
-
if (ctx.dest)
|
|
447
|
-
message += ` -> '${ctx.dest}'`;
|
|
448
|
-
}
|
|
449
|
-
super(message);
|
|
442
|
+
super(message || '');
|
|
450
443
|
this.errno = errno;
|
|
451
444
|
this.code = code;
|
|
452
445
|
Object.assign(this, omit(ctx, 'message'));
|
|
446
|
+
if (!message)
|
|
447
|
+
setUVMessage(this);
|
|
453
448
|
Error.captureStackTrace?.(this, this.constructor);
|
|
454
449
|
}
|
|
455
450
|
toString() {
|
|
@@ -484,7 +479,7 @@ export function UV(code, context, path, dest) {
|
|
|
484
479
|
return err;
|
|
485
480
|
}
|
|
486
481
|
/**
|
|
487
|
-
* Shortcut to easily create an `
|
|
482
|
+
* Shortcut to easily create an `Exception` with a specific error code.
|
|
488
483
|
*/
|
|
489
484
|
export function withErrno(code, message) {
|
|
490
485
|
const err = new Exception(Errno[code], message ?? errnoMessages[Errno[code]]);
|
package/dist/log.js
CHANGED
|
@@ -87,16 +87,8 @@ export function deprecated(symbol) {
|
|
|
87
87
|
function ansi(text, format) {
|
|
88
88
|
return `\x1b[${format}m${text}\x1b[0m`;
|
|
89
89
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
switch (style) {
|
|
93
|
-
case 'ansi':
|
|
94
|
-
return [ansi(text, '2;37')];
|
|
95
|
-
case 'css':
|
|
96
|
-
return ['%c' + text, 'opacity: 0.8; color: white;'];
|
|
97
|
-
default:
|
|
98
|
-
return [text];
|
|
99
|
-
}
|
|
90
|
+
function timestamp(entry) {
|
|
91
|
+
return '[' + (entry.elapsedMs / 1000).toFixed(3).padStart(10) + '] ';
|
|
100
92
|
}
|
|
101
93
|
const levelColor = {
|
|
102
94
|
ansi: {
|
|
@@ -148,26 +140,26 @@ const messageColor = {
|
|
|
148
140
|
*/
|
|
149
141
|
export function fancy({ style, colorize }) {
|
|
150
142
|
return function* (entry) {
|
|
151
|
-
|
|
143
|
+
if (style == 'css')
|
|
144
|
+
yield colorize == 'level' ? '%c%s %c%s' : '%c%s %c%s%s %c%s';
|
|
145
|
+
yield* style == 'ansi' ? [ansi(timestamp(entry), '2;37')] : ['opacity: 0.8; color: white;', timestamp(entry)];
|
|
152
146
|
const levelText = style == 'ansi'
|
|
153
147
|
? [ansi(levels[entry.level].toUpperCase(), levelColor.ansi[entry.level])]
|
|
154
|
-
: [
|
|
148
|
+
: [levelColor.css[entry.level], levels[entry.level].toUpperCase()];
|
|
155
149
|
if (colorize == 'level') {
|
|
156
150
|
yield* levelText;
|
|
157
151
|
yield entry.message;
|
|
158
152
|
return;
|
|
159
153
|
}
|
|
160
|
-
if (entry.level < Level.CRIT)
|
|
154
|
+
if (entry.level < Level.CRIT)
|
|
161
155
|
yield* levelText;
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
if (colorize == 'message')
|
|
156
|
+
if (style == 'ansi')
|
|
165
157
|
yield ansi(entry.message, messageColor.ansi[entry.level]);
|
|
166
158
|
else
|
|
167
|
-
yield* [
|
|
159
|
+
yield* [messageColor.css[entry.level], entry.message];
|
|
168
160
|
};
|
|
169
161
|
}
|
|
170
|
-
let _format = (entry) => [
|
|
162
|
+
let _format = (entry) => [timestamp(entry), entry.message];
|
|
171
163
|
export function format(entry) {
|
|
172
164
|
const formatted = _format(entry);
|
|
173
165
|
return typeof formatted == 'string' ? [formatted] : Array.from(formatted);
|