@augment-vir/common
Advanced tools
Comparing version 14.3.1 to 14.4.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.executeAndReturnError = exports.wrapInTry = exports.ensureError = exports.extractErrorMessage = exports.combineErrorMessages = exports.combineErrors = void 0; | ||
exports.executeAndReturnError = exports.wrapInTry = exports.ensureErrorAndPrependMessage = exports.ensureError = exports.extractErrorMessage = exports.combineErrorMessages = exports.combineErrors = void 0; | ||
const __1 = require(".."); | ||
@@ -23,23 +23,32 @@ function combineErrors(errors) { | ||
exports.combineErrorMessages = combineErrorMessages; | ||
function extractErrorMessage(error) { | ||
if (!error) { | ||
function extractErrorMessage(maybeError) { | ||
if (!maybeError) { | ||
return ''; | ||
} | ||
if (error instanceof Error) { | ||
return error.message; | ||
if (maybeError instanceof Error) { | ||
return maybeError.message; | ||
} | ||
else if ((0, __1.typedHasProperty)(maybeError, 'message')) { | ||
return String(maybeError.message); | ||
} | ||
else { | ||
return String(error); | ||
return String(maybeError); | ||
} | ||
} | ||
exports.extractErrorMessage = extractErrorMessage; | ||
function ensureError(input) { | ||
if (input instanceof Error) { | ||
return input; | ||
function ensureError(maybeError) { | ||
if (maybeError instanceof Error) { | ||
return maybeError; | ||
} | ||
else { | ||
return new Error(extractErrorMessage(input)); | ||
return new Error(extractErrorMessage(maybeError)); | ||
} | ||
} | ||
exports.ensureError = ensureError; | ||
function ensureErrorAndPrependMessage(maybeError, prependMessage) { | ||
const error = ensureError(maybeError); | ||
error.message = `${prependMessage}: ${error.message}`; | ||
return error; | ||
} | ||
exports.ensureErrorAndPrependMessage = ensureErrorAndPrependMessage; | ||
function wrapInTry(inputs) { | ||
@@ -46,0 +55,0 @@ try { |
@@ -1,2 +0,2 @@ | ||
import { isPromiseLike, isTruthy } from '..'; | ||
import { isPromiseLike, isTruthy, typedHasProperty, } from '..'; | ||
export function combineErrors(errors) { | ||
@@ -18,21 +18,29 @@ if (!errors || errors.length === 0) { | ||
} | ||
export function extractErrorMessage(error) { | ||
if (!error) { | ||
export function extractErrorMessage(maybeError) { | ||
if (!maybeError) { | ||
return ''; | ||
} | ||
if (error instanceof Error) { | ||
return error.message; | ||
if (maybeError instanceof Error) { | ||
return maybeError.message; | ||
} | ||
else if (typedHasProperty(maybeError, 'message')) { | ||
return String(maybeError.message); | ||
} | ||
else { | ||
return String(error); | ||
return String(maybeError); | ||
} | ||
} | ||
export function ensureError(input) { | ||
if (input instanceof Error) { | ||
return input; | ||
export function ensureError(maybeError) { | ||
if (maybeError instanceof Error) { | ||
return maybeError; | ||
} | ||
else { | ||
return new Error(extractErrorMessage(input)); | ||
return new Error(extractErrorMessage(maybeError)); | ||
} | ||
} | ||
export function ensureErrorAndPrependMessage(maybeError, prependMessage) { | ||
const error = ensureError(maybeError); | ||
error.message = `${prependMessage}: ${error.message}`; | ||
return error; | ||
} | ||
export function wrapInTry(inputs) { | ||
@@ -39,0 +47,0 @@ try { |
@@ -8,4 +8,5 @@ import { RequireExactlyOne } from 'type-fest'; | ||
export declare function combineErrorMessages(errors?: ReadonlyArray<Error | string | undefined> | undefined): string; | ||
export declare function extractErrorMessage(error: unknown): string; | ||
export declare function ensureError(input: unknown): Error; | ||
export declare function extractErrorMessage(maybeError: unknown): string; | ||
export declare function ensureError(maybeError: unknown): Error; | ||
export declare function ensureErrorAndPrependMessage(maybeError: unknown, prependMessage: string): Error; | ||
export type TryWrapInputs<CallbackReturn, FallbackReturn> = { | ||
@@ -12,0 +13,0 @@ callback: () => CallbackReturn; |
{ | ||
"name": "@augment-vir/common", | ||
"version": "14.3.1", | ||
"version": "14.4.0", | ||
"homepage": "https://github.com/electrovir/augment-vir/tree/main/packages/common", | ||
@@ -5,0 +5,0 @@ "bugs": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
141819
3327
2