@augment-vir/common 14.3.0 → 14.4.0
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.executeAndReturnError = exports.wrapInTry = exports.ensureError = exports.extractErrorMessage = exports.combineErrorMessages = exports.combineErrors = void 0;
|
|
3
|
+
exports.executeAndReturnError = exports.wrapInTry = exports.ensureErrorAndPrependMessage = exports.ensureError = exports.extractErrorMessage = exports.combineErrorMessages = exports.combineErrors = void 0;
|
|
4
4
|
const __1 = require("..");
|
|
5
5
|
function combineErrors(errors) {
|
|
6
6
|
if (!errors || errors.length === 0) {
|
|
@@ -20,27 +20,36 @@ function combineErrorMessages(errors) {
|
|
|
20
20
|
return errors.map(extractErrorMessage).filter(__1.isTruthy).join('\n');
|
|
21
21
|
}
|
|
22
22
|
exports.combineErrorMessages = combineErrorMessages;
|
|
23
|
-
function extractErrorMessage(
|
|
24
|
-
if (!
|
|
23
|
+
function extractErrorMessage(maybeError) {
|
|
24
|
+
if (!maybeError) {
|
|
25
25
|
return '';
|
|
26
26
|
}
|
|
27
|
-
if (
|
|
28
|
-
return
|
|
27
|
+
if (maybeError instanceof Error) {
|
|
28
|
+
return maybeError.message;
|
|
29
|
+
}
|
|
30
|
+
else if ((0, __1.typedHasProperty)(maybeError, 'message')) {
|
|
31
|
+
return String(maybeError.message);
|
|
29
32
|
}
|
|
30
33
|
else {
|
|
31
|
-
return String(
|
|
34
|
+
return String(maybeError);
|
|
32
35
|
}
|
|
33
36
|
}
|
|
34
37
|
exports.extractErrorMessage = extractErrorMessage;
|
|
35
|
-
function ensureError(
|
|
36
|
-
if (
|
|
37
|
-
return
|
|
38
|
+
function ensureError(maybeError) {
|
|
39
|
+
if (maybeError instanceof Error) {
|
|
40
|
+
return maybeError;
|
|
38
41
|
}
|
|
39
42
|
else {
|
|
40
|
-
return new Error(extractErrorMessage(
|
|
43
|
+
return new Error(extractErrorMessage(maybeError));
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
exports.ensureError = ensureError;
|
|
47
|
+
function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
48
|
+
const error = ensureError(maybeError);
|
|
49
|
+
error.message = `${prependMessage}: ${error.message}`;
|
|
50
|
+
return error;
|
|
51
|
+
}
|
|
52
|
+
exports.ensureErrorAndPrependMessage = ensureErrorAndPrependMessage;
|
|
44
53
|
function wrapInTry(inputs) {
|
|
45
54
|
try {
|
|
46
55
|
return inputs.callback();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPromiseLike, isTruthy } from '..';
|
|
1
|
+
import { isPromiseLike, isTruthy, typedHasProperty, } from '..';
|
|
2
2
|
export function combineErrors(errors) {
|
|
3
3
|
if (!errors || errors.length === 0) {
|
|
4
4
|
return undefined;
|
|
@@ -15,25 +15,33 @@ export function combineErrorMessages(errors) {
|
|
|
15
15
|
}
|
|
16
16
|
return errors.map(extractErrorMessage).filter(isTruthy).join('\n');
|
|
17
17
|
}
|
|
18
|
-
export function extractErrorMessage(
|
|
19
|
-
if (!
|
|
18
|
+
export function extractErrorMessage(maybeError) {
|
|
19
|
+
if (!maybeError) {
|
|
20
20
|
return '';
|
|
21
21
|
}
|
|
22
|
-
if (
|
|
23
|
-
return
|
|
22
|
+
if (maybeError instanceof Error) {
|
|
23
|
+
return maybeError.message;
|
|
24
|
+
}
|
|
25
|
+
else if (typedHasProperty(maybeError, 'message')) {
|
|
26
|
+
return String(maybeError.message);
|
|
24
27
|
}
|
|
25
28
|
else {
|
|
26
|
-
return String(
|
|
29
|
+
return String(maybeError);
|
|
27
30
|
}
|
|
28
31
|
}
|
|
29
|
-
export function ensureError(
|
|
30
|
-
if (
|
|
31
|
-
return
|
|
32
|
+
export function ensureError(maybeError) {
|
|
33
|
+
if (maybeError instanceof Error) {
|
|
34
|
+
return maybeError;
|
|
32
35
|
}
|
|
33
36
|
else {
|
|
34
|
-
return new Error(extractErrorMessage(
|
|
37
|
+
return new Error(extractErrorMessage(maybeError));
|
|
35
38
|
}
|
|
36
39
|
}
|
|
40
|
+
export function ensureErrorAndPrependMessage(maybeError, prependMessage) {
|
|
41
|
+
const error = ensureError(maybeError);
|
|
42
|
+
error.message = `${prependMessage}: ${error.message}`;
|
|
43
|
+
return error;
|
|
44
|
+
}
|
|
37
45
|
export function wrapInTry(inputs) {
|
|
38
46
|
try {
|
|
39
47
|
return inputs.callback();
|
|
@@ -5,8 +5,9 @@ export declare function combineErrors(errors: ReadonlyArray<never>): undefined;
|
|
|
5
5
|
export declare function combineErrors(errors: ReadonlyArray<Error>): Error | undefined;
|
|
6
6
|
export declare function combineErrors(errors?: undefined): undefined;
|
|
7
7
|
export declare function combineErrorMessages(errors?: ReadonlyArray<Error | string | undefined> | undefined): string;
|
|
8
|
-
export declare function extractErrorMessage(
|
|
9
|
-
export declare function ensureError(
|
|
8
|
+
export declare function extractErrorMessage(maybeError: unknown): string;
|
|
9
|
+
export declare function ensureError(maybeError: unknown): Error;
|
|
10
|
+
export declare function ensureErrorAndPrependMessage(maybeError: unknown, prependMessage: string): Error;
|
|
10
11
|
export type TryWrapInputs<CallbackReturn, FallbackReturn> = {
|
|
11
12
|
callback: () => CallbackReturn;
|
|
12
13
|
} & RequireExactlyOne<{
|