Skip to content

spotify-cli


spotify-cli / errors

errors ​

Custom error types and exit codes for the Spotify CLI.

All CLI errors are represented as SpotifyCliError instances, each carrying a numeric ExitCode so the process can exit with a machine-readable status. Errors include a structured ErrorCode for machine-readable error classification.

Classes ​

SpotifyCliError ​

Defined in: src/errors.ts:81

Error class for all CLI-specific errors.

Carries an ExitCode and structured ErrorDetails that get serialized into the JSON error output.

Extends ​

  • Error

Constructors ​

Constructor ​

new SpotifyCliError(message, exitCode, details): SpotifyCliError

Defined in: src/errors.ts:82

Parameters ​
message ​

string

exitCode ​

ExitCode

The process exit code to use when this error is handled.

details ​

ErrorDetails

Structured data included in the JSON error output.

Returns ​

SpotifyCliError

Overrides ​

Error.constructor

Properties ​

cause? ​

optional cause: unknown

Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26

The cause of the error.

Inherited from ​

Error.cause

details ​

readonly details: ErrorDetails

Defined in: src/errors.ts:87

Structured data included in the JSON error output.

exitCode ​

readonly exitCode: ExitCode

Defined in: src/errors.ts:85

The process exit code to use when this error is handled.

message ​

message: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1077

Inherited from ​

Error.message

name ​

name: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1076

Inherited from ​

Error.name

stack? ​

optional stack: string

Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078

Inherited from ​

Error.stack

stackTraceLimit ​

static stackTraceLimit: number

Defined in: node_modules/@types/node/globals.d.ts:67

The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

Inherited from ​

Error.stackTraceLimit

Methods ​

captureStackTrace() ​
Call Signature ​

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/@types/node/globals.d.ts:51

Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

js
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`

The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

js
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
Parameters ​
targetObject ​

object

constructorOpt? ​

Function

Returns ​

void

Inherited from ​

Error.captureStackTrace

Call Signature ​

static captureStackTrace(targetObject, constructorOpt?): void

Defined in: node_modules/bun-types/globals.d.ts:1042

Create .stack property on a target object

Parameters ​
targetObject ​

object

constructorOpt? ​

Function

Returns ​

void

Inherited from ​

Error.captureStackTrace

isError() ​
Call Signature ​

static isError(error): error is Error

Defined in: node_modules/typescript/lib/lib.esnext.error.d.ts:23

Indicates whether the argument provided is a built-in Error instance or not.

Parameters ​
error ​

unknown

Returns ​

error is Error

Inherited from ​

Error.isError

Call Signature ​

static isError(value): value is Error

Defined in: node_modules/bun-types/globals.d.ts:1037

Check if a value is an instance of Error

Parameters ​
value ​

unknown

The value to check

Returns ​

value is Error

True if the value is an instance of Error, false otherwise

Inherited from ​

Error.isError

prepareStackTrace() ​

static prepareStackTrace(err, stackTraces): any

Defined in: node_modules/@types/node/globals.d.ts:55

Parameters ​
err ​

Error

stackTraces ​

CallSite[]

Returns ​

any

See ​

https://v8.dev/docs/stack-trace-api#customizing-stack-traces

Inherited from ​

Error.prepareStackTrace

Interfaces ​

ErrorDetails ​

Defined in: src/errors.ts:67

Structured error details included in JSON error output.

Indexable ​

[key: string]: unknown

Properties ​

code ​

code: ErrorCode

Defined in: src/errors.ts:68

deprecated? ​

optional deprecated: boolean

Defined in: src/errors.ts:71

path? ​

optional path: string

Defined in: src/errors.ts:70

status? ​

optional status: number

Defined in: src/errors.ts:69

Type Aliases ​

ErrorCode ​

ErrorCode = typeof ErrorCode[keyof typeof ErrorCode]

Defined in: src/errors.ts:40

Union of all valid error code strings.


ExitCode ​

ExitCode = typeof ExitCode[keyof typeof ExitCode]

Defined in: src/errors.ts:23

Union of all valid exit code values.

Variables ​

ErrorCode ​

const ErrorCode: object

Defined in: src/errors.ts:40

Machine-readable error codes for structured error handling.

These enable consumers to programmatically handle specific error conditions without parsing error message strings.

Type Declaration ​

API_ERROR ​

readonly API_ERROR: "API_ERROR" = "API_ERROR"

DEPRECATED ​

readonly DEPRECATED: "DEPRECATED" = "DEPRECATED"

FORBIDDEN ​

readonly FORBIDDEN: "FORBIDDEN" = "FORBIDDEN"

INVALID_ARGUMENT ​

readonly INVALID_ARGUMENT: "INVALID_ARGUMENT" = "INVALID_ARGUMENT"

MISSING_ARGUMENT ​

readonly MISSING_ARGUMENT: "MISSING_ARGUMENT" = "MISSING_ARGUMENT"

MISSING_CLIENT_ID ​

readonly MISSING_CLIENT_ID: "MISSING_CLIENT_ID" = "MISSING_CLIENT_ID"

NETWORK_ERROR ​

readonly NETWORK_ERROR: "NETWORK_ERROR" = "NETWORK_ERROR"

NOT_FOUND ​

readonly NOT_FOUND: "NOT_FOUND" = "NOT_FOUND"

NOT_LOGGED_IN ​

readonly NOT_LOGGED_IN: "NOT_LOGGED_IN" = "NOT_LOGGED_IN"

RATE_LIMITED ​

readonly RATE_LIMITED: "RATE_LIMITED" = "RATE_LIMITED"

TOKEN_CORRUPTED ​

readonly TOKEN_CORRUPTED: "TOKEN_CORRUPTED" = "TOKEN_CORRUPTED"

TOKEN_EXPIRED ​

readonly TOKEN_EXPIRED: "TOKEN_EXPIRED" = "TOKEN_EXPIRED"

UNKNOWN_COMMAND ​

readonly UNKNOWN_COMMAND: "UNKNOWN_COMMAND" = "UNKNOWN_COMMAND"


ExitCode ​

const ExitCode: object

Defined in: src/errors.ts:23

Numeric exit codes used by the CLI process.

CodeMeaning
0Success
1Invalid arguments
2Authentication failure
3Spotify API error
4Network error

Type Declaration ​

API ​

readonly API: 3 = 3

ARGS ​

readonly ARGS: 1 = 1

AUTH ​

readonly AUTH: 2 = 2

NETWORK ​

readonly NETWORK: 4 = 4

SUCCESS ​

readonly SUCCESS: 0 = 0

Functions ​

apiError() ​

apiError(message, details?): SpotifyCliError

Defined in: src/errors.ts:117

Creates an error for Spotify API failures (exit code 3).

Parameters ​

message ​

string

Human-readable description of the API error.

details? ​

Partial<ErrorDetails>

Structured data (HTTP status, path, etc). code defaults to API_ERROR.

Returns ​

SpotifyCliError


argsError() ​

argsError(message, code?): SpotifyCliError

Defined in: src/errors.ts:99

Creates an error for invalid CLI arguments (exit code 1).

Parameters ​

message ​

string

Human-readable description of the argument error.

code? ​

ErrorCode = ErrorCode.MISSING_ARGUMENT

Specific error code (defaults to MISSING_ARGUMENT).

Returns ​

SpotifyCliError


authError() ​

authError(message, code?): SpotifyCliError

Defined in: src/errors.ts:108

Creates an error for authentication failures (exit code 2).

Parameters ​

message ​

string

Human-readable description of the auth error.

code? ​

ErrorCode = ErrorCode.NOT_LOGGED_IN

Specific error code (defaults to NOT_LOGGED_IN).

Returns ​

SpotifyCliError


networkError() ​

networkError(message): SpotifyCliError

Defined in: src/errors.ts:125

Creates an error for network failures (exit code 4).

Parameters ​

message ​

string

Human-readable description of the network error.

Returns ​

SpotifyCliError

MIT Licensed. Not affiliated with or endorsed by Spotify AB.