Documentation for Simbo's Packages
    Preparing search index...

    Module @simbo/user-facing-error - v1.0.2

    User Facing Error

    📦 @simbo/user-facing-error

    A custom Error class for creating user-facing error messages.

    It supports additional hints to guide users toward resolving issues, while maintaining full compatibility with standard JavaScript Error behavior.

    • Extends the native Error class
    • Includes an optional hint (string or true for a generic hint)
    • Supports standard ErrorOptions including cause
    • Static from method for wrapping other errors with a new message
    • Fully typed TypeScript API
    • One dependency (@simbo/stringify-error)

    Install @simbo/user-facing-error from the npm registry:

    npm i [-D] @simbo/user-facing-error
    

    For a complete API reference, see the documentation.

    import { UserFacingError } from '@simbo/user-facing-error';

    // Creating the simplest user-facing error:
    throw new UserFacingError('Operation cancelled');

    // Creating a basic user-facing error with a hint:
    throw new UserFacingError('Invalid input', 'Use --help for usage information');

    // Adding a generic hint:
    // (You have to provide a hint when catching this error.)
    throw new UserFacingError('Command failed', true);

    // Using another error (or anything else) as `cause`:
    const cause = new Error('Underlying error');
    throw new UserFacingError('Top-level error', {
    cause,
    hint: 'Retry with valid credentials',
    });

    // Wrapping another error:
    try {
    // some failing operation
    } catch (err) {
    throw UserFacingError.from(
    err,
    'Operation failed',
    'Check your network connection',
    );
    }

    MIT © Simon Lepel

    Classes

    UserFacingError

    Interfaces

    Options

    Type Aliases

    Hint
    SecondParam