@vestra-player/sdk - v1.11.3
    Preparing search index...

    A definite refusal from the player (or the plugin runner), with a stable code. Plugin code sees it as a PluginError (an Error with code); branch on code, never on message.

    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 plain Error instead 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).

    The test proves the plugin sees a refused write as an error with code failed. host.handle replaces the test host's handler for one request method; the HostError it throws travels back like the player's own refusal, so the call rejects with that code and is not retried. host.reset puts the default handler back for later steps.

    import assert from "node:assert/strict";
    import { HostError, startPlugin } from "@vestra-player/sdk/testing";
    import activate from "../main.ts";

    const { host, plugin, stop } = await startPlugin(activate, {
    directory: new URL("..", import.meta.url),
    });
    host.handle("clipboard.writeText", () => {
    throw new HostError("failed", "the system refused the write");
    });
    await assert.rejects(plugin.clipboard.writeText("x"), { code: "failed" });
    host.reset("clipboard.writeText"); // writes succeed again
    await stop();

    A definite refusal, as opposed to a lost reply: the SDK does not retry it, and the plugin sees an Error with code.

    1.0.0

    Hierarchy

    Index
    • A refusal with this code, as the player would send it.

      Parameters

      • code: string

        The stable error code the caller will see as error.code.

      • message: string

        Human-readable detail (not for branching on).

      Returns HostError

    • 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
      • OptionalconstructorOpt: Function

      Returns void

    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.

    code: string

    The stable error code, e.g. "invalid", "stale", "unavailable".

    cause?: unknown
    name: string
    message: string
    stack?: string