kerium 1.3.0 → 1.3.2
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 +5 -0
- package/dist/error.js +8 -3
- package/package.json +1 -1
package/dist/error.d.ts
CHANGED
|
@@ -420,6 +420,10 @@ export interface ExceptionJSON {
|
|
|
420
420
|
dest?: string;
|
|
421
421
|
syscall?: string;
|
|
422
422
|
}
|
|
423
|
+
/**
|
|
424
|
+
* Set the message of an exception to the UV-style message.
|
|
425
|
+
*/
|
|
426
|
+
export declare function setUVMessage<T extends ExceptionJSON>(ex: T): T;
|
|
423
427
|
/**
|
|
424
428
|
* An error with additional information about what happened.
|
|
425
429
|
*
|
|
@@ -453,5 +457,6 @@ export declare function UV(this: void, code: keyof typeof Errno, context?: Excep
|
|
|
453
457
|
* Shortcut to easily create an `ErrnoException` with a specific error code.
|
|
454
458
|
*/
|
|
455
459
|
export declare function withErrno(this: void, code: keyof typeof Errno, message?: string): Exception;
|
|
460
|
+
export declare function rethrow(syscall: string, path?: string, dest?: string): (e: Exception) => never;
|
|
456
461
|
export declare function rethrow(extra: ExceptionExtra): (e: Exception) => never;
|
|
457
462
|
export {};
|
package/dist/error.js
CHANGED
|
@@ -406,7 +406,10 @@ export function strerror(errno) {
|
|
|
406
406
|
const _errno = typeof errno == 'string' ? Errno[errno] : errno;
|
|
407
407
|
return (_errno in errnoMessages ? errnoMessages[_errno] : '');
|
|
408
408
|
}
|
|
409
|
-
|
|
409
|
+
/**
|
|
410
|
+
* Set the message of an exception to the UV-style message.
|
|
411
|
+
*/
|
|
412
|
+
export function setUVMessage(ex) {
|
|
410
413
|
let message = `${ex.code}: ${errnoMessages[ex.errno]}, ${ex.syscall}`;
|
|
411
414
|
if (ex.path)
|
|
412
415
|
message += ` '${ex.path}'`;
|
|
@@ -415,6 +418,7 @@ function setUVMessage(ex) {
|
|
|
415
418
|
if (ex.message)
|
|
416
419
|
message += ` (${ex.message})`;
|
|
417
420
|
ex.message = message;
|
|
421
|
+
return ex;
|
|
418
422
|
}
|
|
419
423
|
/**
|
|
420
424
|
* An error with additional information about what happened.
|
|
@@ -487,9 +491,10 @@ export function withErrno(code, message) {
|
|
|
487
491
|
Error.captureStackTrace?.(err, withErrno);
|
|
488
492
|
return err;
|
|
489
493
|
}
|
|
490
|
-
export function rethrow(extra) {
|
|
494
|
+
export function rethrow(extra, path, dest) {
|
|
495
|
+
const ctx = typeof extra === 'string' ? { syscall: extra, path, dest } : extra;
|
|
491
496
|
return function (e) {
|
|
492
|
-
Object.assign(e,
|
|
497
|
+
Object.assign(e, ctx);
|
|
493
498
|
setUVMessage(e);
|
|
494
499
|
throw e;
|
|
495
500
|
};
|