Skip to content

PluginError

The error raised by a plugin.

It extends DisTubeError, so the code of the error is available with error.errorCode and the error can be caught with instanceof DisTubeError.

T extends PluginErrorCode = PluginErrorCode

new PluginError<T>(
code,
message?,
options?
): PluginError<T>;

Create a plugin error.

T

The error code

string

The message. It defaults to the one of the error code.

Optional options

unknown

The original error that caused this one

PluginError<T>

throw new PluginError(PluginErrorCode.NOT_FOUND);

DisTubeError.constructor

cause?: unknown;

DisTubeError.cause


errorCode: string;

The code of the error, e.g. NO_RESULT.

DisTubeError.errorCode


message: string;

DisTubeError.message


stack?: string;

DisTubeError.stack


transient?: boolean;

Whether the error was caused by a transient failure (e.g. temporary network issue).

DisTubeError.transient


static stackTraceLimit: number;

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.

DisTubeError.stackTraceLimit

get code(): string;

The code of the error, e.g. NO_RESULT.

It is an alias of DisTubeError.errorCode.

string

The code of the error

DisTubeError.code


get name(): string;

The name of the error, with its code.

string

The name of the error, e.g. PluginError [NOT_FOUND]

DisTubeError.name

static captureStackTrace(targetObject, constructorOpt?): void;

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();

object

Function

void

DisTubeError.captureStackTrace


static is(error): error is DisTubeError<any>;

Check whether a value is a DisTubeError.

unknown

The value to test

error is DisTubeError<any>

true when the value is a DisTubeError

DisTubeError.is


static isError(error): error is Error;

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

unknown

error is Error

DisTubeError.isError


static prepareStackTrace(err, stackTraces): any;

Error

CallSite[]

any

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

DisTubeError.prepareStackTrace


static withMessage<T>(
code,
message,
options?
): DisTubeError<T>;

Create a DisTubeError with a custom message.

The default message of an error code is a generic template. Use this factory when you need to tell the user what exactly went wrong, or when you want to keep the original error as the cause of the error.

It is polymorphic: calling it on a subclass creates an instance of that subclass.

T extends string = any

T

The error code

string

The custom message

Optional options

unknown

The original error that caused this one

DisTubeError<T>

The created error

DisTubeError.withMessage