All files / src/utils new-error.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 1/1
100% Lines 4/4

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 16                    32x 18x 18x 18x    
import { Logger } from './logger';
 
/**
 * Creates a new Error object and logs it through the provided logger.
 * This utility function ensures all errors are properly logged before being thrown.
 *
 * @param logger - The logger instance used to record the error
 * @param message - Optional message describing the error
 * @returns A new Error object with the provided message
 */
export function newError(logger: Logger, message?: string): Error {
    const error = new Error(message);
    logger.error(error);
    return error;
}