fix(gateway): include platform and reason in node command rejection error

The generic "node command not allowed" error gives no indication of why the
command was rejected, making it hard to diagnose issues (e.g. running
`nodes notify` against a Linux node that does not declare `system.notify`).

Include the rejection reason and node platform in the error message so
callers can tell whether the command is not supported by the node, not in
the platform allowlist, or the node did not advertise its capabilities.

Fixes #24616

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
(cherry picked from commit e3d74619bc)
This commit is contained in:
justinhuangcode
2026-02-23 17:26:04 +00:00
committed by Peter Steinberger
parent 5de1f540e7
commit d00d814ad1
2 changed files with 23 additions and 2 deletions

View File

@@ -169,10 +169,12 @@ export const browserHandlers: GatewayRequestHandlers = {
allowlist,
});
if (!allowed.ok) {
const platform = nodeTarget.platform ?? "unknown";
const hint = `node command not allowed: ${allowed.reason} (platform: ${platform}, command: browser.proxy)`;
respond(
false,
undefined,
errorShape(ErrorCodes.INVALID_REQUEST, "node command not allowed", {
errorShape(ErrorCodes.INVALID_REQUEST, hint, {
details: { reason: allowed.reason, command: "browser.proxy" },
}),
);

View File

@@ -687,10 +687,11 @@ export const nodeHandlers: GatewayRequestHandlers = {
allowlist,
});
if (!allowed.ok) {
const hint = buildNodeCommandRejectionHint(allowed.reason, command, nodeSession);
respond(
false,
undefined,
errorShape(ErrorCodes.INVALID_REQUEST, "node command not allowed", {
errorShape(ErrorCodes.INVALID_REQUEST, hint, {
details: { reason: allowed.reason, command },
}),
);
@@ -784,3 +785,21 @@ export const nodeHandlers: GatewayRequestHandlers = {
});
},
};
function buildNodeCommandRejectionHint(
reason: string,
command: string,
node: { platform?: string } | undefined,
): string {
const platform = node?.platform ?? "unknown";
if (reason === "command not declared by node") {
return `node command not allowed: the node (platform: ${platform}) does not support "${command}"`;
}
if (reason === "command not allowlisted") {
return `node command not allowed: "${command}" is not in the allowlist for platform "${platform}"`;
}
if (reason === "node did not declare commands") {
return `node command not allowed: the node did not declare any supported commands`;
}
return `node command not allowed: ${reason}`;
}