@simbo/user-facing-error
Version:
A custom Error class for creating user-facing error messages with an optional hint to guide users toward resolving issues.
37 lines (36 loc) • 1.37 kB
TypeScript
import type { Hint, SecondParam } from './user-facing-error.types.js';
/**
* An error that will be displayed to the user.
*
* Beside the main message, it can include an additional hint message to help
* the user resolve the issue.
*
* The hint option can also be `true` to indicate that a generic hint should be
* shown. (e.g. refer to `--help`).
*
* This class extends the standard Error class and also accepts an ErrorOptions
* object including the `hint` property beside other standard error properties
* like `cause`.
*/
export declare class UserFacingError extends Error {
#private;
readonly name = "UserFacingError";
readonly hint: Hint;
/**
* Creates a new UserFacingError instance.
*
* @param message - The main error message.
* @param options - Optional hint or ErrorOptions.
*/
constructor(message: string, options?: SecondParam);
/**
* Creates a UserFacingError from another error, wrapping it with a new message.
* It can also include a hint string or boolean.
*
* @param error - The original error to wrap.
* @param message - The new message for the UserFacingError.
* @param options - Optional hint or ErrorOptions.
* @returns A new UserFacingError instance.
*/
static from(error: unknown, message: string, options?: SecondParam): UserFacingError;
}