@jossmac/lil-libs
    Preparing search index...

    Function ensureError

    • Normalizes unknown thrown input into an Error instance.

      Returns the input unchanged when it is already an Error. Wraps strings in a new Error (empty strings use the fallback message). For error-like objects, copies message and preserves name/stack when present.

      • error: unknown

        Unknown thrown value from a catch block or Promise rejection.

      The same Error when already an instance; a new Error for strings and error-like objects (copying name/stack when present); a serialized fallback for other values.

      ensureError(new Error("boom")); // same Error instance
      ensureError("boom"); // Error("boom")
      ensureError(""); // Error("An unknown error occurred.")
      ensureError({ message: "boom", name: "CustomError" }); // Error with copied name
      ensureError(404); // Error('Error: 404')