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
The process exit code to use when this error is handled.
details
Structured data included in the JSON error output.
Returns
Overrides
Error.constructor
Properties
cause?
optionalcause:unknown
Defined in: node_modules/typescript/lib/lib.es2022.error.d.ts:26
The cause of the error.
Inherited from
Error.cause
details
readonlydetails:ErrorDetails
Defined in: src/errors.ts:87
Structured data included in the JSON error output.
exitCode
readonlyexitCode: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?
optionalstack:string
Defined in: node_modules/typescript/lib/lib.es5.d.ts:1078
Inherited from
Error.stack
stackTraceLimit
staticstackTraceLimit: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
staticcaptureStackTrace(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.
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:
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
staticcaptureStackTrace(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
staticisError(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
staticisError(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()
staticprepareStackTrace(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?
optionaldeprecated:boolean
Defined in: src/errors.ts:71
path?
optionalpath:string
Defined in: src/errors.ts:70
status?
optionalstatus:number
Defined in: src/errors.ts:69
Type Aliases
ErrorCode
Defined in: src/errors.ts:40
Union of all valid error code strings.
ExitCode
Defined in: src/errors.ts:23
Union of all valid exit code values.
Variables
ErrorCode
constErrorCode: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
readonlyAPI_ERROR:"API_ERROR"="API_ERROR"
DEPRECATED
readonlyDEPRECATED:"DEPRECATED"="DEPRECATED"
FORBIDDEN
readonlyFORBIDDEN:"FORBIDDEN"="FORBIDDEN"
INVALID_ARGUMENT
readonlyINVALID_ARGUMENT:"INVALID_ARGUMENT"="INVALID_ARGUMENT"
MISSING_ARGUMENT
readonlyMISSING_ARGUMENT:"MISSING_ARGUMENT"="MISSING_ARGUMENT"
MISSING_CLIENT_ID
readonlyMISSING_CLIENT_ID:"MISSING_CLIENT_ID"="MISSING_CLIENT_ID"
NETWORK_ERROR
readonlyNETWORK_ERROR:"NETWORK_ERROR"="NETWORK_ERROR"
NOT_FOUND
readonlyNOT_FOUND:"NOT_FOUND"="NOT_FOUND"
NOT_LOGGED_IN
readonlyNOT_LOGGED_IN:"NOT_LOGGED_IN"="NOT_LOGGED_IN"
RATE_LIMITED
readonlyRATE_LIMITED:"RATE_LIMITED"="RATE_LIMITED"
TOKEN_CORRUPTED
readonlyTOKEN_CORRUPTED:"TOKEN_CORRUPTED"="TOKEN_CORRUPTED"
TOKEN_EXPIRED
readonlyTOKEN_EXPIRED:"TOKEN_EXPIRED"="TOKEN_EXPIRED"
UNKNOWN_COMMAND
readonlyUNKNOWN_COMMAND:"UNKNOWN_COMMAND"="UNKNOWN_COMMAND"
ExitCode
constExitCode:object
Defined in: src/errors.ts:23
Numeric exit codes used by the CLI process.
| Code | Meaning |
|---|---|
| 0 | Success |
| 1 | Invalid arguments |
| 2 | Authentication failure |
| 3 | Spotify API error |
| 4 | Network error |
Type Declaration
API
readonlyAPI:3=3
ARGS
readonlyARGS:1=1
AUTH
readonlyAUTH:2=2
NETWORK
readonlyNETWORK:4=4
SUCCESS
readonlySUCCESS: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
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
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
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.