All files / utils/converter errorify.ts

100% Statements 3/3
100% Branches 2/2
100% Functions 1/1
100% Lines 2/2

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15                        13x 7x  
/**
 * Converts a given value into an instance of Error.
 *
 * @example
 *
 * ```ts
 * const error = errorify('An error occurred');
 * ```
 *
 * @param {unknown} value - The value to convert into an Error.
 * @returns {Error} The converted Error object.
 */
export const errorify = (value: unknown): Error =>
  value instanceof Error ? value : new Error(String(value), { cause: value });