fix(frida): name the argument each Frida input error rejects (#2217)

Frida session lookups, script lookups, unreadable script files and the
instrument-with-frida PID and script checks returned invalid_request with
no issues, while the remediation told callers to correct the listed
arguments. Attach the session_id, script_id, path, target or script issue
with the reason so CLI and MCP callers can see what to fix.

Fixes #2213

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kaoru0822
2026-10-12 23:00:59 +08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 109769319a
commit 86de439ba4
6 changed files with 146 additions and 9 deletions
@@ -986,3 +986,39 @@ it("serializes script loading against concurrent close and unloads the loaded sc
expect(bindings.device.session.scripts[0]?.isDestroyed).toBe(true);
expect(bindings.device.session.isDetached()).toBe(true);
});
it("names the unknown session or script ID it rejects", async () => {
const { manager, started } = await startLocalAttachedSession();
if (!started.ok) throw started.error;
const missing = "00000000-0000-4000-8000-000000000009";
const sessionIssue = {
path: ["session_id"],
reason: "invalid_value",
message: `No open Frida session ${missing}; start one with start_frida_session.`,
};
for (const result of [
await manager.closeSession(missing),
await manager.resumeSession(missing),
await manager.loadScript(missing, { sourceKind: "inline", source: "" }),
await manager.unloadScript(missing, missing),
])
expect(result).toMatchObject({
ok: false,
error: { _tag: "AnalysisInputError", issues: [sessionIssue] },
});
expect(
await manager.unloadScript(started.value.sessionId, missing),
).toMatchObject({
ok: false,
error: {
issues: [
{
path: ["script_id"],
reason: "invalid_value",
message: `No loaded Frida script ${missing} in this session.`,
},
],
},
});
await manager.closeAll();
});
+27
View File
@@ -0,0 +1,27 @@
import { AnalysisInputError } from "../../domain/analysisErrorCore.js";
/** A session ID that names no open Frida session owned by this process. */
export const unknownFridaSession = (
operation: string,
sessionId: string,
): AnalysisInputError =>
new AnalysisInputError(operation, undefined, [
{
path: ["session_id"],
reason: "invalid_value",
message: `No open Frida session ${sessionId}; start one with start_frida_session.`,
},
]);
/** A script ID that names no loaded script in the selected session. */
export const unknownFridaScript = (
operation: string,
scriptId: string,
): AnalysisInputError =>
new AnalysisInputError(operation, undefined, [
{
path: ["script_id"],
reason: "invalid_value",
message: `No loaded Frida script ${scriptId} in this session.`,
},
]);