Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SfdxError

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.

// 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

      The error name. Defaults to 'SfdxError'.

    • Optional actions: string[]

      The action message(s).

    • Optional exitCode: undefined | number

      The exit code which will be used by SfdxCommand.

    • Optional cause: Error

      The underlying error that caused this error to be raised.

    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

Accessors

code

  • get code(): string
  • set code(code: string): void

Methods

setCommandName

  • setCommandName(commandName: string): SfdxError
  • Sets the name of the command. For convenience this object is returned.

    Parameters

    • commandName: string

      The command name.

    Returns SfdxError

setData

  • An additional payload for the error. For convenience this object is returned.

    Parameters

    • data: unknown

      The payload data.

    Returns SfdxError

toObject

  • toObject(): JsonMap
  • Convert an SfdxError state to an object. Returns a plain object representing the state of this error.

    Returns JsonMap

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

      The values to use for message tokenization.

    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 | string

      The error to convert.

    Returns SfdxError