Skip to content

Commit e8d6012

Browse files
committed
refactor(runtime): build the refusal error inline at both sites, as the vocabulary scan reads them
Claude-Session: https://claude.ai/code/session_01Utp6CXvMJTCqCs1b69pCH7 Co-authored-by: Claude <noreply@anthropic.com>
1 parent b3058a7 commit e8d6012

1 file changed

Lines changed: 13 additions & 17 deletions

File tree

‎packages/runtime/src/sandbox/hook-refusal-catalogue.ts‎

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ type DeclaredAnswer =
406406
* What a declared code answers with — the picked sentence and the status — or
407407
* the loud fault for a reason the code does not declare. Shared by the body
408408
* path and the in-process path so the two cannot answer differently; each
409-
* builds its `SandboxError` from it with the code it read ({@link refusalError}).
409+
* builds its `SandboxError` from it with the code it read, in one shape.
410410
*
411411
* [#36877, ruling 7178348458 terms 1–3] A throw that names an ordered
412412
* `reasons` list instead of one `reason` is answered line by line:
@@ -469,20 +469,6 @@ function declaredAnswer(
469469
return { message, status };
470470
}
471471

472-
/** The refusal error both run paths throw for a declared answer: one shape, so every door builds one envelope. */
473-
function refusalError(
474-
logMessage: string,
475-
code: string,
476-
answer: { message: string; status: number; refusals?: DeclaredRefusalLine[] },
477-
): SandboxError {
478-
return new SandboxError(logMessage, answer.message, {
479-
code,
480-
status: answer.status,
481-
userMessage: answer.message,
482-
...(answer.refusals !== undefined ? { refusals: answer.refusals } : {}),
483-
});
484-
}
485-
486472
/**
487473
* Answer a sandboxed hook body's throw against the hook's refusal catalogue.
488474
* Returns the error to throw in its place — `err` itself whenever the
@@ -551,7 +537,12 @@ function resolveSandboxedRefusal(
551537
}
552538
const answer = declaredAnswer(owner, code, entry, sandboxRefusalAddressOf(err), locale, opts);
553539
if ('fault' in answer) return answer.fault;
554-
return refusalError(err.message, code, answer);
540+
return new SandboxError(err.message, answer.message, {
541+
code,
542+
status: answer.status,
543+
userMessage: answer.message,
544+
...(answer.refusals !== undefined ? { refusals: answer.refusals } : {}),
545+
});
555546
}
556547

557548
// ── The in-process half (#33214, ruling 6879477573 letter A) ─────────────────
@@ -743,5 +734,10 @@ export function resolveInProcessHookRefusal(
743734
});
744735
const answer = declaredAnswer(owner, code, entry, address, engineCtx?.session?.locale, opts);
745736
if ('fault' in answer) return answer.fault;
746-
return refusalError(`hook '${String(hook.name)}' threw: ${flattenThrown(err)}`, code, answer);
737+
return new SandboxError(`hook '${String(hook.name)}' threw: ${flattenThrown(err)}`, answer.message, {
738+
code,
739+
status: answer.status,
740+
userMessage: answer.message,
741+
...(answer.refusals !== undefined ? { refusals: answer.refusals } : {}),
742+
});
747743
}

0 commit comments

Comments
 (0)