mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 11:43:20 +00:00
fix(process): classify GDB, Apktool and Java-probe launch failures through the shared launch owner (#11631)
* fix(process): classify GDB, Apktool and Java-probe launch failures through the shared launch owner GDB session start, the Apktool version probe and the Jadx and Ghidra Java probes read a launcher's error with launcherFailureOf and report host capacity (EAGAIN, ENOMEM, EMFILE, ENFILE) and E2BIG through the shared classifyLaunchFailure, keeping their own unavailable reports for refusals. Only a launcher-raised errno counts as a launch failure, and a GDB launch failure no longer retries the MI2 dialect. The refusal-only classifyLaunchFailure helper is removed. Refs #11614 * fix(process): name the environment as the E2BIG repair for fixed-argument launches GDB, the Apktool version probe and the Jadx and Ghidra Java probes launch fixed arguments, so selecting less input cannot shrink an oversized launch. The shared launch report takes fixedArguments and then tells the caller to shrink the environment REA runs with. Launch tests check structured facts and guidance delivery instead of whole sentences. * fix(process): report which launch input an E2BIG refusal leaves to shrink as a structured fact
This commit is contained in:
1 parent
0035d8edb3
commit
e5cf021ca6
13 files changed
+371
-56
No files matched your search
@@ -18,7 +18,7 @@ import {
|
||||
withVerifierFixture,
|
||||
} from "./lib/verifier-fixture.mjs";
|
||||
import { createVerifierCommands } from "./lib/verify-commands.mjs";
|
||||
import { classifyLaunchFailure } from "../dist/process/launchFailure.js";
|
||||
import { launcherFailureOf } from "../dist/process/launchFailure.js";
|
||||
|
||||
// Compile every regular expression and schema the packaged server advertises,
|
||||
// in every schema profile, with the engines and validators clients and
|
||||
@@ -80,11 +80,13 @@ const runHelper = async (
|
||||
}));
|
||||
}
|
||||
} catch (error) {
|
||||
const refusal = classifyLaunchFailure(error);
|
||||
if (refusal !== undefined)
|
||||
// Only a launch refusal means the engine is not installed; a host
|
||||
// capacity failure is a broken check.
|
||||
const launch = launcherFailureOf(error);
|
||||
if (launch?.kind === "missing" || launch?.kind === "not_executable")
|
||||
return engines.map((engine) => ({
|
||||
...engine,
|
||||
unavailable: `${command} could not start (${refusal.code})`,
|
||||
unavailable: `${command} could not start (${launch.code})`,
|
||||
}));
|
||||
// A helper that started but failed is a broken check, not a missing
|
||||
// engine, so it fails even when engines are optional.
|
||||
|
||||
@@ -18,6 +18,8 @@ import {
|
||||
import type { OwnedProviderProcessSpawnOptions } from "../process/ProviderProcess.js";
|
||||
import { failedInspectionDescriptor } from "../../tests/fixtures/processInspectionCleanup.js";
|
||||
import { createInspectionResources } from "../../tests/fixtures/inspectionResources.js";
|
||||
import { spawnFailure } from "../../tests/support/process/spawnFailure.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
|
||||
it.each([false, true])(
|
||||
"retains physical preparation instead of reporting a Java refusal (batch: %s)",
|
||||
@@ -210,3 +212,78 @@ it.each(["probe", "configuration"] as const)(
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ code: "ENOENT", thrown: "launcher", expected: "runtime_missing" },
|
||||
{ code: "ENOENT", thrown: "reader", expected: "runtime_unavailable" },
|
||||
{ code: "EACCES", thrown: "launcher", expected: "runtime_unavailable" },
|
||||
] as const)(
|
||||
"reads only a launcher's $code as a Java runtime refusal ($thrown)",
|
||||
async ({ code, thrown, expected }) => {
|
||||
const resources = createInspectionResources();
|
||||
const prepare = vi
|
||||
.spyOn(systemProcessOwnershipHost, "prepare")
|
||||
.mockResolvedValue(undefined);
|
||||
try {
|
||||
const result = await inspectJadxJava(
|
||||
"/selected/java",
|
||||
{},
|
||||
{
|
||||
resourceOwner: resources.owner,
|
||||
launcher: async () => {
|
||||
throw thrown === "launcher"
|
||||
? spawnFailure(code, "/selected/java")
|
||||
: Object.assign(new Error("read failed"), { code });
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result).toMatchObject({ ok: false, error: { code: expected } });
|
||||
} finally {
|
||||
prepare.mockRestore();
|
||||
await resources.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["EAGAIN", true, {}],
|
||||
// The probe's arguments are fixed, so only the environment can shrink.
|
||||
["E2BIG", false, { oversized_launch_input: "environment" }],
|
||||
] as const)(
|
||||
"reports a host launch constraint %s as a resource constraint, not a Java refusal",
|
||||
async (code, retryable, facts) => {
|
||||
const resources = createInspectionResources();
|
||||
const prepare = vi
|
||||
.spyOn(systemProcessOwnershipHost, "prepare")
|
||||
.mockResolvedValue(undefined);
|
||||
try {
|
||||
const result: unknown = await inspectJadxJava(
|
||||
"/selected/java",
|
||||
{},
|
||||
{
|
||||
resourceOwner: resources.owner,
|
||||
launcher: async () => {
|
||||
throw spawnFailure(code, "/selected/java");
|
||||
},
|
||||
},
|
||||
).catch((cause: unknown) => cause);
|
||||
expect(result).toBeInstanceOf(AnalysisError);
|
||||
if (!(result instanceof AnalysisError)) throw result;
|
||||
expect(projectAnalysisError(result)).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable,
|
||||
details: {
|
||||
diagnostics: {
|
||||
system_code: code,
|
||||
command: "/selected/java",
|
||||
java_executable: "/selected/java",
|
||||
...facts,
|
||||
},
|
||||
},
|
||||
});
|
||||
} finally {
|
||||
prepare.mockRestore();
|
||||
await resources.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -1,6 +1,7 @@
|
||||
import { capturedProviderOutput } from "../process/capturedProviderOutput.js";
|
||||
import type { ProcessInspectionFailure } from "../process/ProcessInspectionCleanup.js";
|
||||
import { classifyLaunchFailureCode } from "../process/launchFailure.js";
|
||||
import { launcherFailureOf } from "../process/launchFailure.js";
|
||||
import { classifyLaunchFailure } from "../process/classifyProviderOutcome.js";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import type { RetainedResourceScope } from "../ports/AnalysisProvider.js";
|
||||
import {
|
||||
@@ -164,6 +165,7 @@ export const inspectJadxJava = async (
|
||||
"jadx",
|
||||
operation,
|
||||
);
|
||||
const hostConstraint = hostLaunchConstraint(command, cause);
|
||||
let primary: AnalysisError;
|
||||
if (observed !== undefined && !observed.ok) {
|
||||
if (cleanups.length === 0) return observed;
|
||||
@@ -244,6 +246,21 @@ export const inspectJadxJava = async (
|
||||
cause,
|
||||
...(output === undefined ? {} : { capturedOutput: output }),
|
||||
});
|
||||
} else if (hostConstraint !== undefined) {
|
||||
// The host, not the selected Java runtime, refused this launch.
|
||||
primary = classifyLaunchFailure(hostConstraint, {
|
||||
providerId: "jadx",
|
||||
operation,
|
||||
fixedArguments: true,
|
||||
command: java,
|
||||
details: {
|
||||
cause,
|
||||
diagnostics: {
|
||||
java_executable: java,
|
||||
phase: "module-inspection",
|
||||
},
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const failure = commandProbeRefusal(
|
||||
java,
|
||||
@@ -273,6 +290,17 @@ export const inspectJadxJava = async (
|
||||
}
|
||||
};
|
||||
|
||||
/** A launch the host refused for capacity or argument size, not the runtime's fault. */
|
||||
const hostLaunchConstraint = (
|
||||
command: Pick<OwnedCommandFailure, "processError"> | undefined,
|
||||
cause: unknown,
|
||||
) => {
|
||||
const launch = launcherFailureOf(command?.processError ?? cause);
|
||||
return launch?.kind === "host-exhausted" || launch?.kind === "argument-list"
|
||||
? launch
|
||||
: undefined;
|
||||
};
|
||||
|
||||
const commandProbeRefusal = (
|
||||
java: string,
|
||||
command:
|
||||
@@ -289,7 +317,7 @@ const commandProbeRefusal = (
|
||||
command?.processError ?? (cause instanceof Error ? cause : undefined);
|
||||
const systemCode =
|
||||
processError === undefined ? undefined : Reflect.get(processError, "code");
|
||||
const missing = classifyLaunchFailureCode(systemCode)?.kind === "missing";
|
||||
const missing = launcherFailureOf(processError)?.kind === "missing";
|
||||
const limited = command?.reason === "output-limit";
|
||||
const timedOut = command?.reason === "timeout";
|
||||
return {
|
||||
|
||||
@@ -10,7 +10,8 @@ import { ApktoolCommandCleanup } from "./ApktoolCommandCleanup.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../process/DarwinProcessRunTokenReader.js";
|
||||
import { classifyLaunchFailure } from "../process/launchFailure.js";
|
||||
import { launcherFailureOf } from "../process/launchFailure.js";
|
||||
import { classifyLaunchFailure } from "../process/classifyProviderOutcome.js";
|
||||
import {
|
||||
AnalysisResourceConstraintError,
|
||||
AnalysisTimeoutError,
|
||||
@@ -519,9 +520,25 @@ const versionProbeFailure = (
|
||||
...apktoolVersionProbeTimeoutGuidance(),
|
||||
},
|
||||
);
|
||||
const refusal = classifyLaunchFailure(cause);
|
||||
if (refusal !== undefined) {
|
||||
const execDenied = refusal.kind === "not_executable";
|
||||
const launch = launcherFailureOf(cause);
|
||||
// The host, not the selected launcher, refused this launch.
|
||||
if (launch?.kind === "host-exhausted" || launch?.kind === "argument-list")
|
||||
return classifyLaunchFailure(launch, {
|
||||
providerId: "apktool",
|
||||
operation: "inspect_apktool_client",
|
||||
command: selection.command,
|
||||
fixedArguments: true,
|
||||
selection: APKTOOL_COMMAND_ENV,
|
||||
details: {
|
||||
cause,
|
||||
diagnostics: {
|
||||
selected_command: selection.command,
|
||||
command_source: selection.commandSource,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (launch?.kind === "missing" || launch?.kind === "not_executable") {
|
||||
const execDenied = launch.kind === "not_executable";
|
||||
return new ApktoolConfigurationFailure(
|
||||
execDenied ? "command_not_executable" : "command_missing",
|
||||
execDenied
|
||||
@@ -531,7 +548,7 @@ const versionProbeFailure = (
|
||||
? APKTOOL_NOT_EXECUTABLE_REMEDIATION
|
||||
: APKTOOL_MISSING_REMEDIATION,
|
||||
{
|
||||
filesystem_error: refusal.code,
|
||||
filesystem_error: launch.code,
|
||||
selected_command: selection.command,
|
||||
command_source: selection.commandSource,
|
||||
},
|
||||
|
||||
@@ -5,7 +5,9 @@ import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisTimeoutError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
import { spawnFailure } from "../../tests/support/process/spawnFailure.js";
|
||||
import {
|
||||
OwnedCommandFailure,
|
||||
runOwnedCommand,
|
||||
@@ -205,7 +207,7 @@ it.each([
|
||||
["ENOENT", "command_missing"],
|
||||
])("distinguishes launcher spawn %s", async (code, expected) => {
|
||||
vi.mocked(runOwnedCommand).mockRejectedValueOnce(
|
||||
Object.assign(new Error(code), { code }),
|
||||
spawnFailure(code, selection.command),
|
||||
);
|
||||
await expect(
|
||||
inspectApktoolClient(selection, commands, {
|
||||
@@ -221,6 +223,47 @@ it.each([
|
||||
});
|
||||
});
|
||||
|
||||
it("does not read an errno from outside the launcher as a launch refusal", async () => {
|
||||
vi.mocked(runOwnedCommand).mockRejectedValueOnce(
|
||||
Object.assign(new Error("read failed"), { code: "ENOENT" }),
|
||||
);
|
||||
await expect(
|
||||
inspectApktoolClient(selection, commands, {
|
||||
environment: {},
|
||||
platform: "linux",
|
||||
}),
|
||||
).rejects.toMatchObject({ code: "version_unresolved" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
["EAGAIN", true],
|
||||
["E2BIG", false],
|
||||
])(
|
||||
"reports a host launch constraint %s as a resource constraint, not a launcher fault",
|
||||
async (code, retryable) => {
|
||||
vi.mocked(runOwnedCommand).mockRejectedValueOnce(
|
||||
spawnFailure(code, selection.command),
|
||||
);
|
||||
const failure = await inspectApktoolClient(selection, commands, {
|
||||
environment: {},
|
||||
platform: "linux",
|
||||
}).catch((cause: unknown) => cause);
|
||||
expect(failure).toBeInstanceOf(AnalysisError);
|
||||
expect(projectAnalysisError(failure as AnalysisError)).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable,
|
||||
details: {
|
||||
operation: "inspect_apktool_client",
|
||||
diagnostics: {
|
||||
system_code: code,
|
||||
command: selection.command,
|
||||
selected_command: selection.command,
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("reports version capture overflow as a resource constraint with the selected launcher", async () => {
|
||||
vi.mocked(runOwnedCommand).mockRejectedValueOnce(
|
||||
new OwnedCommandFailure("output-limit", "too much output"),
|
||||
|
||||
@@ -18,7 +18,14 @@ import {
|
||||
import { persistentDebuggerHostSupported } from "../process/PersistentDebuggerHost.js";
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { AbortedWait, waitForAbortable } from "../process/AbortablePromise.js";
|
||||
import { classifyLaunchFailure } from "../process/launchFailure.js";
|
||||
import {
|
||||
describeLaunchFailure,
|
||||
launcherFailureOf,
|
||||
} from "../process/launchFailure.js";
|
||||
import {
|
||||
classifyLaunchFailure,
|
||||
type LaunchUnavailableFailure,
|
||||
} from "../process/classifyProviderOutcome.js";
|
||||
import { snapshotGdbCommandRecords } from "./GdbCommandRecords.js";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { constants as fsConstants } from "node:fs";
|
||||
@@ -108,22 +115,28 @@ const copiedTimeoutGuidance = (
|
||||
: { diagnostics: cause.diagnostics }),
|
||||
...(cause.limit === undefined ? {} : { limit: cause.limit }),
|
||||
});
|
||||
/** A host executable refusal cannot be repaired by changing MI dialect. */
|
||||
class GdbExecutableRefusal extends AnalysisCapabilityUnavailableError {
|
||||
constructor(command: string, systemCode: string, cause: Error) {
|
||||
super("gdb", "start_gdb_session", cause.message, {
|
||||
cause,
|
||||
userMessage: `Could not launch the selected GDB executable ${JSON.stringify(command)} (${systemCode}).`,
|
||||
/** The selected GDB executable could not be started. */
|
||||
const gdbLaunchUnavailable = (
|
||||
command: string,
|
||||
failure: LaunchUnavailableFailure,
|
||||
details: AnalysisErrorOptions,
|
||||
): AnalysisCapabilityUnavailableError => {
|
||||
const reason = `Could not launch the selected GDB executable ${JSON.stringify(command)} (${describeLaunchFailure(failure)}).`;
|
||||
return new AnalysisCapabilityUnavailableError(
|
||||
"gdb",
|
||||
"start_gdb_session",
|
||||
reason,
|
||||
{
|
||||
...details,
|
||||
userMessage: reason,
|
||||
remediationAction:
|
||||
"Set REA_GDB_COMMAND to an installed executable GDB command, or make that command available on PATH. Check execute permission on the command and search permission on its parent directories before retrying.",
|
||||
diagnostics: {
|
||||
boundary: "provider-launch",
|
||||
command,
|
||||
system_code: systemCode,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
/** Launch failures: changing the MI dialect cannot start the executable. */
|
||||
const gdbLaunchFailures = new WeakSet<AnalysisError>();
|
||||
|
||||
const MAX_COMMAND_OUTPUT_RECORDS = 16_384;
|
||||
const MAX_MI_LINE_BYTES = 16 * 1024 * 1024;
|
||||
@@ -551,7 +564,7 @@ export class GdbSessionManager {
|
||||
return mi3.ok ||
|
||||
signal.aborted ||
|
||||
this.#sessions.has(id) ||
|
||||
mi3.error instanceof GdbExecutableRefusal
|
||||
gdbLaunchFailures.has(mi3.error)
|
||||
? mi3
|
||||
: this.#startProtocol(
|
||||
id,
|
||||
@@ -591,11 +604,22 @@ export class GdbSessionManager {
|
||||
cause instanceof AnalysisCancelledError
|
||||
)
|
||||
return err(cancelledBy("start_gdb_session", carriedReason(cause)));
|
||||
const refusal = classifyLaunchFailure(cause);
|
||||
if (refusal !== undefined && cause instanceof Error)
|
||||
return err(
|
||||
new GdbExecutableRefusal(this.#command, refusal.code, cause),
|
||||
);
|
||||
const launch = launcherFailureOf(cause);
|
||||
if (launch !== undefined) {
|
||||
const command = this.#command;
|
||||
const failure = classifyLaunchFailure(launch, {
|
||||
providerId: "gdb",
|
||||
operation: "start_gdb_session",
|
||||
command,
|
||||
fixedArguments: true,
|
||||
selection: "REA_GDB_COMMAND",
|
||||
details: { cause },
|
||||
unavailable: (unavailable, details) =>
|
||||
gdbLaunchUnavailable(command, unavailable, details),
|
||||
});
|
||||
gdbLaunchFailures.add(failure);
|
||||
return err(failure);
|
||||
}
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"gdb",
|
||||
|
||||
@@ -12,6 +12,8 @@ import { projectGhidraDoctorInspection } from "./GhidraDoctor.js";
|
||||
import { describe, expect, it, afterEach } from "vitest";
|
||||
import { probeGhidraJava, parseGhidraJavaOutput } from "./GhidraJavaProbe.js";
|
||||
import { createInspectionResources } from "../../tests/fixtures/inspectionResources.js";
|
||||
import { spawnFailure } from "../../tests/support/process/spawnFailure.js";
|
||||
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
||||
let resources = createInspectionResources();
|
||||
afterEach(async () => {
|
||||
await resources.close();
|
||||
@@ -52,7 +54,7 @@ describe("Ghidra Java prerequisite process facts", () => {
|
||||
])(
|
||||
"keeps %s distinct from other runtime failures",
|
||||
async (code, expected) => {
|
||||
const error = Object.assign(new Error(`controlled ${code}`), { code });
|
||||
const error = spawnFailure(code, "/selected/bin/java");
|
||||
const result = await probeGhidraJava(
|
||||
"/selected/bin/java",
|
||||
{},
|
||||
@@ -76,6 +78,57 @@ describe("Ghidra Java prerequisite process facts", () => {
|
||||
},
|
||||
);
|
||||
|
||||
it("does not read an errno from outside the launcher as a missing runtime", async () => {
|
||||
const result = await probeGhidraJava(
|
||||
"/selected/bin/java",
|
||||
{},
|
||||
{
|
||||
resourceOwner: resources.owner,
|
||||
launcher: async () => {
|
||||
throw Object.assign(new Error("read failed"), { code: "ENOENT" });
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
ok: false,
|
||||
error: { _tag: "GhidraJavaProbeFailure", code: "runtime_unavailable" },
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["EAGAIN", true],
|
||||
["E2BIG", false],
|
||||
])(
|
||||
"reports a host launch constraint %s as a resource constraint, not a runtime fault",
|
||||
async (code, retryable) => {
|
||||
const result = await probeGhidraJava(
|
||||
"/selected/bin/java",
|
||||
{},
|
||||
{
|
||||
resourceOwner: resources.owner,
|
||||
launcher: async () => {
|
||||
throw spawnFailure(code, "/selected/bin/java");
|
||||
},
|
||||
},
|
||||
);
|
||||
expect(result.ok).toBe(false);
|
||||
if (result.ok) return;
|
||||
expect(result.error).toBeInstanceOf(AnalysisError);
|
||||
if (!(result.error instanceof AnalysisError)) return;
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "resource_constraint",
|
||||
retryable,
|
||||
details: {
|
||||
diagnostics: {
|
||||
system_code: code,
|
||||
command: "/selected/bin/java",
|
||||
java_executable: "/selected/bin/java",
|
||||
},
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps raw byte counts and both streams on a nonzero exit", () => {
|
||||
const result = probe({
|
||||
status: 7,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { ProcessInspectionFailure } from "../process/ProcessInspectionCleanup.js";
|
||||
import { HOST_PLATFORM } from "../platform/HostPlatform.js";
|
||||
import { classifyLaunchFailureCode } from "../process/launchFailure.js";
|
||||
import { launcherFailureOf } from "../process/launchFailure.js";
|
||||
import { classifyLaunchFailure } from "../process/classifyProviderOutcome.js";
|
||||
import { GhidraAdmissionError } from "./GhidraAdmissionError.js";
|
||||
import {
|
||||
retainOwnedCommandCleanup,
|
||||
@@ -291,6 +292,19 @@ const observeGhidraJava = async (
|
||||
} else if (cause instanceof AnalysisError) {
|
||||
primary = cause;
|
||||
}
|
||||
const launch = launcherFailureOf(commandFailure?.processError ?? cause);
|
||||
if (
|
||||
primary === undefined &&
|
||||
(launch?.kind === "host-exhausted" || launch?.kind === "argument-list")
|
||||
)
|
||||
// The host, not the selected Java runtime, refused this launch.
|
||||
primary = classifyLaunchFailure(launch, {
|
||||
providerId: "ghidra",
|
||||
operation: "ghidra:java",
|
||||
fixedArguments: true,
|
||||
command,
|
||||
details: { cause, diagnostics: { java_executable: command } },
|
||||
});
|
||||
if (primary === undefined) {
|
||||
const code =
|
||||
commandFailure?.reason === "timeout"
|
||||
@@ -301,7 +315,7 @@ const observeGhidraJava = async (
|
||||
const failed: GhidraJavaProbeFailure = {
|
||||
_tag: "GhidraJavaProbeFailure",
|
||||
code:
|
||||
classifyLaunchFailureCode(code)?.kind === "missing"
|
||||
launch?.kind === "missing"
|
||||
? "runtime_missing"
|
||||
: "runtime_unavailable",
|
||||
detail: `${command}: ${errorMessage(cause)}`,
|
||||
|
||||
@@ -68,6 +68,12 @@ export interface LaunchFailureContext {
|
||||
readonly selection?: string;
|
||||
/** Bytes of the refused argument list, when the caller measured them. */
|
||||
readonly argumentBytes?: number;
|
||||
/**
|
||||
* The command's arguments do not depend on the request, so an oversized
|
||||
* launch (E2BIG) can only be repaired by shrinking the environment REA
|
||||
* passes to it.
|
||||
*/
|
||||
readonly fixedArguments?: boolean;
|
||||
/**
|
||||
* The provider's report that it cannot be started, such as a message naming
|
||||
* its configured executable. Without it the shared report names the
|
||||
@@ -139,8 +145,19 @@ export const classifyLaunchFailure = (
|
||||
},
|
||||
{
|
||||
...details,
|
||||
diagnostics: {
|
||||
...details.diagnostics,
|
||||
// Fixed arguments leave the environment as the only input to shrink.
|
||||
oversized_launch_input:
|
||||
context.fixedArguments === true
|
||||
? "environment"
|
||||
: "request_and_environment",
|
||||
},
|
||||
retryable: false,
|
||||
remediationAction: `Select less input for one call, or pass large values through a file, then retry; ${unchanged}. An unchanged request fails the same way.`,
|
||||
remediationAction:
|
||||
context.fixedArguments === true
|
||||
? `This command's arguments do not depend on the request, so the environment REA passes to it is too large. Remove large or unneeded variables from the environment REA runs with, then retry; ${unchanged}. Retrying in the same environment fails the same way.`
|
||||
: `Select less input for one call, or pass large values through a file, then retry; ${unchanged}. An unchanged request fails the same way.`,
|
||||
},
|
||||
);
|
||||
case "missing":
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
classifyLaunchFailure,
|
||||
classifyLaunchFailureCode,
|
||||
classifyLaunchErrno,
|
||||
describeLaunchFailure,
|
||||
@@ -19,9 +18,6 @@ it.each([
|
||||
["EISDIR", "not_executable"],
|
||||
])("classifies spawn %s as %s", (code, kind) => {
|
||||
expect(classifyLaunchFailureCode(code)).toEqual({ kind, code });
|
||||
expect(
|
||||
classifyLaunchFailure(Object.assign(new Error(code), { code })),
|
||||
).toEqual({ kind, code });
|
||||
});
|
||||
|
||||
it.each([["EAGAIN"], ["EMFILE"], ["ETIMEDOUT"], [1], [null], ["toString"]])(
|
||||
|
||||
@@ -89,14 +89,6 @@ export const classifyLaunchFailureCode = (
|
||||
return kind === undefined ? undefined : { kind, code };
|
||||
};
|
||||
|
||||
/** Classify a spawn failure; undefined when it was not a launch refusal. */
|
||||
export const classifyLaunchFailure = (
|
||||
cause: unknown,
|
||||
): LaunchRefusal | undefined =>
|
||||
cause instanceof Error && "code" in cause
|
||||
? classifyLaunchFailureCode(cause.code)
|
||||
: undefined;
|
||||
|
||||
/**
|
||||
* Name the executable on an errno Node threw synchronously from `spawn`.
|
||||
* Node emits ENOENT and EACCES as `spawn <path>` with `path`, but throws
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PassThrough } from "node:stream";
|
||||
import { spawnFailure } from "../../support/process/spawnFailure.js";
|
||||
|
||||
import pino from "pino";
|
||||
import { expect, it, vi } from "vitest";
|
||||
@@ -144,12 +145,7 @@ it.each(["ENOENT", "EACCES", "EPERM"] as const)(
|
||||
"keeps selected GDB launch recovery in the public CLI for %s",
|
||||
async (code) => {
|
||||
const selected = "/selected/gdb command";
|
||||
const launchFailure = Object.assign(
|
||||
new Error(`spawn ${selected} ${code}`),
|
||||
{
|
||||
code,
|
||||
},
|
||||
);
|
||||
const launchFailure = spawnFailure(code, selected);
|
||||
const spawnProcess = vi.fn(async () => {
|
||||
throw launchFailure;
|
||||
});
|
||||
@@ -170,7 +166,7 @@ it.each(["ENOENT", "EACCES", "EPERM"] as const)(
|
||||
message: expect.stringContaining(JSON.stringify(selected)),
|
||||
remediation: { action: expect.stringContaining("REA_GDB_COMMAND") },
|
||||
details: {
|
||||
reason: launchFailure.message,
|
||||
reason: expect.stringContaining(JSON.stringify(selected)),
|
||||
diagnostics: {
|
||||
boundary: "provider-launch",
|
||||
command: selected,
|
||||
|
||||
@@ -34,6 +34,7 @@ import {
|
||||
stopOwnedDebuggerProcess,
|
||||
type OwnedDebuggerStopResult,
|
||||
} from "../../../src/process/ownedDebuggerSession.js";
|
||||
import { spawnFailure } from "../../support/process/spawnFailure.js";
|
||||
import { parseLinuxProcessStat } from "../../../src/process/LinuxProcessStat.js";
|
||||
import {
|
||||
answerFakeGdbStartup,
|
||||
@@ -1956,6 +1957,61 @@ it("uses a fallback message when the process launcher rejects without an Error",
|
||||
expect(attempts).toBe(2);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
code: "EAGAIN",
|
||||
tag: "AnalysisResourceConstraintError",
|
||||
projected: { code: "resource_constraint", retryable: true },
|
||||
boundary: "host-capacity",
|
||||
},
|
||||
{
|
||||
code: "E2BIG",
|
||||
tag: "AnalysisResourceConstraintError",
|
||||
// GDB's arguments are fixed, so the repair names the environment.
|
||||
projected: { code: "resource_constraint", retryable: false },
|
||||
boundary: "provider-launch",
|
||||
facts: { oversized_launch_input: "environment" },
|
||||
},
|
||||
{
|
||||
code: "EIO",
|
||||
tag: "AnalysisCapabilityUnavailableError",
|
||||
projected: {
|
||||
code: "capability_unavailable",
|
||||
remediation: { action: expect.stringContaining("REA_GDB_COMMAND") },
|
||||
},
|
||||
boundary: "provider-launch",
|
||||
},
|
||||
])(
|
||||
"classifies a $code launch failure once without retrying another MI dialect",
|
||||
async ({ code, tag, projected, boundary, facts }) => {
|
||||
let attempts = 0;
|
||||
const manager = managerWithFakeSpawner(async () => {
|
||||
attempts += 1;
|
||||
throw spawnFailure(code, "fake-gdb");
|
||||
});
|
||||
|
||||
const started = await manager.start();
|
||||
|
||||
expect(attempts).toBe(1);
|
||||
expect(started.ok).toBe(false);
|
||||
if (!started.ok) {
|
||||
expect(started.error._tag).toBe(tag);
|
||||
expect(projectAnalysisError(started.error)).toMatchObject({
|
||||
...projected,
|
||||
details: {
|
||||
diagnostics: {
|
||||
boundary,
|
||||
system_code: code,
|
||||
syscall: "spawn fake-gdb",
|
||||
command: "fake-gdb",
|
||||
...facts,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it("returns startup timeout when the MI prompt never arrives", async () => {
|
||||
const provider = await createProvider(
|
||||
"process.stdin.resume(); setInterval(() => {}, 1000);\n",
|
||||
|
||||
Reference in new issue
Block a user