A refusal with this code, as the player would send it.
The stable error code the caller will see as error.code.
Human-readable detail (not for branching on).
StaticcaptureCreates 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();
OptionalconstructorOpt: FunctionStaticprepareStaticstackThe 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.
The stable error code, e.g. "invalid", "stale", "unavailable".
OptionalcauseOptionalstack
A definite refusal from the player (or the plugin runner), with a stable
code. Plugin code sees it as aPluginError(anErrorwithcode); branch oncode, never onmessage.In tests, throw one from a TestHost.handle override to simulate the player refusing a request: the SDK treats it exactly like a real refusal (the call rejects with that
code, nothing is retried). Throwing a plainErrorinstead simulates a lost reply, which makes the SDK run its recovery path (asking the host about the operation again).Common codes:
stale(the condition no longer holds; nothing was done),invalid(bad argument),missing(unknown target),builtin-only(a built-in-only request from another plugin),busy,conflict,unavailable,unsupported(refused, not executed),backend(load or parse failure),failed,timeout,aborted,limit(a player limit such as the command count),disabled(the plugin is stopping).Example: Simulate the player refusing a clipboard write in a test
The test proves the plugin sees a refused write as an error with code
failed.host.handlereplaces the test host's handler for one request method; theHostErrorit throws travels back like the player's own refusal, so the call rejects with thatcodeand is not retried.host.resetputs the default handler back for later steps.Remarks
A definite refusal, as opposed to a lost reply: the SDK does not retry it, and the plugin sees an
Errorwithcode.Since
1.0.0