HookForceClaimedError

HookForceClaimedError is thrown when awaiting a hook whose token another workflow run took over with createHook({ experimental_force: true }). The hook is disposed and receives no further payloads; the error names the run that now owns the token. See the hook-force-claimed error guide for how to react.

import { createHook } from "workflow";
import { HookForceClaimedError } from "workflow/errors";

export async function channelWorkflow(channelId: string) {
  "use workflow";

  const hook = createHook<{ text: string }>({ token: `channel:${channelId}` });

  try {
    const message = await hook;
    return { message };
  } catch (error) {
    if (HookForceClaimedError.is(error)) {
      console.log(
        `Token "${error.token}" now belongs to run ${error.claimedByRunId}`
      );
      return { replacedBy: error.claimedByRunId };
    }
    throw error;
  }
}

API signature

Properties

NameTypeDescription
tokenstringThe hook token that was taken over.
claimedByRunIdstringThe run that took the token.
claimedByHookIdstringThe hook in that run the token now belongs to, when known.
messagestringThe error message.

Static methods

HookForceClaimedError.is(value)

Type-safe check for HookForceClaimedError instances. Preferred over instanceof because it works across module boundaries and virtual machine contexts.

import { HookForceClaimedError } from "workflow/errors"
declare const error: unknown; // @setup

if (HookForceClaimedError.is(error)) {
  // error is typed as HookForceClaimedError
}