CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-aggregate-error

Create an error from multiple errors

94

1.28x
Overview
Eval results
Files

task.mdevals/scenario-1/

Error Normalizer

Build a utility that accepts multiple error-like values and normalizes them into standard Error instances. The utility should handle different input formats and ensure they are all properly converted to Error objects.

Requirements

Input Handling

Your utility must accept an array containing any combination of:

  • Native JavaScript Error instances
  • Plain objects with a message property (may include other metadata like code)
  • String values

Normalization Rules

  1. Error instances are kept as-is without modification
  2. Plain objects are converted to Error instances while preserving all properties
  3. String values are wrapped in a new Error with the string as the message

Output

  • Return all normalized errors as an array
  • Maintain the original input order
  • Ensure the returned collection cannot be modified externally

Test Cases

  • An array with Error instances returns them unchanged @test
  • An array with plain objects {message: 'text', code: 'E001'} converts them to Error instances with all properties preserved @test
  • An array with string values ['error1', 'error2'] wraps each in a new Error instance @test
  • A mixed array [new Error('a'), 'b', {message: 'c'}] normalizes each according to its type @test

Implementation

@generates

API

/**
 * Normalizes multiple error-like values into Error instances.
 */
class ErrorNormalizer {
  /**
   * Creates a new ErrorNormalizer.
   * @param {Array} inputs - Array of Error instances, objects, or strings
   */
  constructor(inputs);

  /**
   * Returns the normalized errors.
   * @returns {Array<Error>} Array of Error instances
   */
  get errors();
}

module.exports = ErrorNormalizer;

Dependencies { .dependencies }

aggregate-error { .dependency }

Provides error aggregation and normalization capabilities.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-aggregate-error

tile.json