Options
All
  • Public
  • Public/Protected
  • All
Menu

A generalized sfdx error which also contains an action. The action is used in the CLI to help guide users past the error.

To throw an error in a synchronous function you must either pass the error message and actions directly to the constructor, e.g.

example

// To load a message bundle: Messages.importMessagesDirectory(__dirname); this.messages = Messages.loadMessages('myPackageName', 'myBundleName'); // Note that __dirname should contain a messages folder.

// To throw an error associated with the message from the bundle: throw SfdxError.create('myPackageName', 'myBundleName', 'MyErrorMessageKey', [messageToken1]);

// To throw a non-bundle based error: throw new SfdxError(myErrMsg, 'MyErrorName');

Hierarchy

  • NamedError
    • SfdxError

Index

Constructors

constructor

  • new SfdxError(message: string, name?: undefined | string, actions?: string[], exitCode?: undefined | number, cause?: Error): SfdxError
  • Create an SfdxError.

    Parameters

    • message: string

      The error message.

    • Optional name: undefined | string
    • Optional actions: string[]
    • Optional exitCode: undefined | number
    • Optional cause: Error

    Returns SfdxError

Properties

Optional actions

actions: string[]

Action messages. Hints to the users regarding what can be done to fix related issues.

Optional cause

cause: NamedErrorLike

Optional commandName

commandName: undefined | string

The related command name for this error.

data

data: any

exitCode

exitCode: number

SfdxCommand can return this process exit code.

fullStack

fullStack: string | undefined

message

message: string

The message string. Error.message

name

name: string

Optional stack

stack: undefined | string

Methods

setCommandName

  • setCommandName(commandName: string): SfdxError
  • Sets the name of the command.

    Parameters

    • commandName: string

      The command name.

    Returns SfdxError

    For convenience this object is returned.

setData

  • An additional payload for the error.

    Parameters

    • data: unknown

      The payload data.

    Returns SfdxError

    For convenience this object is returned.

toObject

  • toObject(): object
  • Convert an SfdxError's state to an object.

    Returns object

    A plain object representing the state of this error.

Static create

  • Create a new SfdxError.

    Parameters

    • packageName: string

      The message package name used to create the SfdxError.

    • bundleName: string

      The message bundle name used to create the SfdxError.

    • key: string

      The key within the bundle for the message.

    • Optional tokens: Tokens

    Returns SfdxError

  • Create a new SfdxError.

    Parameters

    • errorConfig: SfdxErrorConfig

      The SfdxErrorConfig object used to create the SfdxError.

    Returns SfdxError

Static wrap

  • Convert an Error to an SfdxError.

    Parameters

    • err: Error

      The error to convert.

    Returns SfdxError