fix(ghidra): keep JVM warnings out of LaunchSupport output (#1698)
* fix(ghidra): keep JVM warnings out of LaunchSupport output Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(ghidra): retain LaunchSupport warnings in session diagnostics * fix(ghidra): select helper logging flags by observed JVM identity * fix(ghidra): preserve diagnostics through typed failure projection --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
morluto
parent
0043d9b134
commit
e20994a8ea
@@ -1,3 +1,5 @@
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
|
||||
/** Stable tags exposed by safe analysis-error projections. */
|
||||
const ANALYSIS_ERROR_TAGS = [
|
||||
"AnalysisProtocolError",
|
||||
@@ -51,6 +53,8 @@ export interface AnalysisCleanupObservation {
|
||||
|
||||
/** Optional provider-neutral context that must survive typed error projection. */
|
||||
export interface AnalysisErrorOptions extends ErrorOptions {
|
||||
/** Producer-owned, caller-safe facts retained through every typed projection. */
|
||||
readonly diagnostics?: Readonly<Record<string, JsonValue>> | undefined;
|
||||
readonly capturedOutput?: AnalysisCapturedOutput | undefined;
|
||||
readonly cleanup?: AnalysisCleanupObservation | undefined;
|
||||
readonly partialObservation?: AnalysisPartialObservation | undefined;
|
||||
@@ -58,12 +62,17 @@ export interface AnalysisErrorOptions extends ErrorOptions {
|
||||
|
||||
/** Base class for expected analysis, provider, and session failures. */
|
||||
export abstract class AnalysisError extends Error {
|
||||
readonly diagnostics: Readonly<Record<string, JsonValue>> | undefined;
|
||||
readonly capturedOutput: AnalysisCapturedOutput | undefined;
|
||||
readonly cleanup: AnalysisCleanupObservation | undefined;
|
||||
readonly cleanupIncomplete: boolean;
|
||||
readonly cleanupResources: readonly string[];
|
||||
constructor(message: string, options?: AnalysisErrorOptions) {
|
||||
super(message, options);
|
||||
this.diagnostics =
|
||||
options?.diagnostics === undefined
|
||||
? undefined
|
||||
: structuredClone(options.diagnostics);
|
||||
this.capturedOutput =
|
||||
options?.capturedOutput === undefined
|
||||
? undefined
|
||||
|
||||
@@ -403,25 +403,33 @@ describe("analysis error projection: provider failures", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("preserves detached, actionable provider diagnostics", () => {
|
||||
const diagnostics = {
|
||||
runtime_root: "/tmp/rea-ghidra-fixture",
|
||||
profile_digest: "a".repeat(64),
|
||||
exit_code: 1,
|
||||
};
|
||||
const error = new ProviderAdapterError("ghidra", "health", {
|
||||
diagnostics,
|
||||
});
|
||||
it.each(["adapter", "cancelled", "timeout"])(
|
||||
"preserves detached, actionable diagnostics for %s errors",
|
||||
(kind) => {
|
||||
const diagnostics = {
|
||||
runtime_root: "/tmp/rea-ghidra-fixture",
|
||||
profile_digest: "a".repeat(64),
|
||||
exit_code: 1,
|
||||
};
|
||||
const error =
|
||||
kind === "adapter"
|
||||
? new ProviderAdapterError("ghidra", "health", { diagnostics })
|
||||
: kind === "cancelled"
|
||||
? new AnalysisCancelledError("health", { diagnostics })
|
||||
: new AnalysisTimeoutError("health", 250, { diagnostics });
|
||||
|
||||
expect(error.diagnostics).not.toBe(diagnostics);
|
||||
expect(projectAnalysisError(error)).toMatchObject({
|
||||
details: {
|
||||
provider_id: "ghidra",
|
||||
operation: "health",
|
||||
diagnostics,
|
||||
},
|
||||
});
|
||||
});
|
||||
expect(error.diagnostics).not.toBe(diagnostics);
|
||||
expect(projectAnalysisError(error)).toMatchObject({
|
||||
details: {
|
||||
...(kind === "adapter" ? { provider_id: "ghidra" } : {}),
|
||||
operation: "health",
|
||||
diagnostics,
|
||||
},
|
||||
});
|
||||
diagnostics.exit_code = 2;
|
||||
expect(error.diagnostics?.exit_code).toBe(1);
|
||||
},
|
||||
);
|
||||
|
||||
it("maps the Linux startup compatibility exit codes without host internals", () => {
|
||||
const expected = [
|
||||
|
||||
@@ -52,6 +52,9 @@ export const projectAnalysisError = (
|
||||
const primaryDetails = errorDetails(error);
|
||||
const details = {
|
||||
...primaryDetails,
|
||||
...(error.diagnostics === undefined
|
||||
? {}
|
||||
: { diagnostics: error.diagnostics }),
|
||||
...(error.cleanupIncomplete
|
||||
? {
|
||||
cleanup: "incomplete",
|
||||
@@ -358,9 +361,6 @@ const providerErrorDetails = (
|
||||
resources: [...error.cleanupResources],
|
||||
}
|
||||
: {}),
|
||||
...(error.diagnostics === undefined
|
||||
? {}
|
||||
: { diagnostics: error.diagnostics }),
|
||||
};
|
||||
if (error instanceof BrowserObservationError) {
|
||||
const primaryReason = primaryBrowserFailureReason(error);
|
||||
|
||||
@@ -3,14 +3,74 @@ import { expect, it } from "vitest";
|
||||
import {
|
||||
AnalysisInputError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisCancelledError,
|
||||
AnalysisTimeoutError,
|
||||
AnalysisArtifactChangedError,
|
||||
AnalysisOutputError,
|
||||
AnalysisResourceConstraintError,
|
||||
} from "./analysisErrorCore.js";
|
||||
import { projectAnalysisError } from "./analysisErrorProjection.js";
|
||||
import { ProviderCleanupError } from "./providerCleanupError.js";
|
||||
import { ProviderAdapterError } from "./providerAdapterError.js";
|
||||
import {
|
||||
redactExplicitFailure,
|
||||
redactExplicitPointer,
|
||||
} from "./explicitSensitiveFailure.js";
|
||||
|
||||
const context = {
|
||||
diagnostics: {
|
||||
note: "explicit-secret warning",
|
||||
nested: { "explicit-secret-key": 5, observed: 7 },
|
||||
caller_path: "/tmp/password-fixture?token=public-value",
|
||||
},
|
||||
capturedOutput: {
|
||||
stdout: "explicit-secret output",
|
||||
stderr: "public stderr",
|
||||
stdout_bytes: 22,
|
||||
truncated: false,
|
||||
},
|
||||
};
|
||||
|
||||
it.each([
|
||||
new AnalysisCancelledError("inspect", context),
|
||||
new AnalysisTimeoutError("inspect", 250, context),
|
||||
new AnalysisInputError("inspect", context),
|
||||
new AnalysisAccessDeniedError("inspect", "/public", "EACCES", context),
|
||||
new AnalysisArtifactChangedError("inspect", "/public", "changed", context),
|
||||
new AnalysisOutputError("inspect", "invalid", context),
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"provider",
|
||||
"inspect",
|
||||
"unsupported",
|
||||
context,
|
||||
),
|
||||
new AnalysisResourceConstraintError(
|
||||
"inspect",
|
||||
"memory",
|
||||
"capacity",
|
||||
null,
|
||||
context,
|
||||
),
|
||||
new ProviderAdapterError("provider", "inspect", context),
|
||||
])("preserves sanitized common context for $._tag", (error) => {
|
||||
const sanitized = redactExplicitFailure(error, ["explicit-secret"]);
|
||||
expect(sanitized._tag).toBe(error._tag);
|
||||
const projected = projectAnalysisError(sanitized);
|
||||
expect(projected.details).toMatchObject({
|
||||
diagnostics: {
|
||||
note: "[REDACTED] warning",
|
||||
nested: { observed: 7 },
|
||||
caller_path: context.diagnostics.caller_path,
|
||||
},
|
||||
captured_output: {
|
||||
stdout: "[REDACTED] output",
|
||||
stdout_bytes: 22,
|
||||
stderr: "public stderr",
|
||||
},
|
||||
});
|
||||
expect(JSON.stringify(projected)).not.toContain("explicit-secret");
|
||||
});
|
||||
|
||||
it.each([
|
||||
["/metadata/private~1~0/numeric", ["private/~"], "/metadata"],
|
||||
["/metadata/private/child", ["private"], "/metadata"],
|
||||
|
||||
@@ -6,6 +6,8 @@ import {
|
||||
AnalysisOutputError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisResourceConstraintError,
|
||||
AnalysisCancelledError,
|
||||
AnalysisTimeoutError,
|
||||
} from "./analysisErrorCore.js";
|
||||
import { redactExplicitText } from "./explicitSensitiveValues.js";
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
@@ -72,24 +74,57 @@ export const redactExplicitFailure = (
|
||||
if (typeof value === "object" && value !== null) return diagnostics(value);
|
||||
return value;
|
||||
};
|
||||
const context = {
|
||||
cause: error,
|
||||
...(error.diagnostics === undefined
|
||||
? {}
|
||||
: { diagnostics: diagnostics(error.diagnostics) }),
|
||||
...(error.capturedOutput === undefined
|
||||
? {}
|
||||
: {
|
||||
capturedOutput: {
|
||||
...error.capturedOutput,
|
||||
stdout: text(error.capturedOutput.stdout),
|
||||
stderr: text(error.capturedOutput.stderr),
|
||||
},
|
||||
}),
|
||||
...(error.cleanup === undefined
|
||||
? {}
|
||||
: {
|
||||
cleanup: {
|
||||
reason: text(error.cleanup.reason),
|
||||
resources: error.cleanup.resources.map(text),
|
||||
},
|
||||
}),
|
||||
};
|
||||
if (error instanceof AnalysisCancelledError)
|
||||
return new AnalysisCancelledError(error.operation, {
|
||||
...context,
|
||||
partialObservation: error.partialObservation,
|
||||
});
|
||||
if (error instanceof AnalysisTimeoutError)
|
||||
return new AnalysisTimeoutError(error.operation, error.timeoutMs, {
|
||||
...context,
|
||||
partialObservation: error.partialObservation,
|
||||
});
|
||||
if (error instanceof AnalysisAccessDeniedError)
|
||||
return new AnalysisAccessDeniedError(
|
||||
error.operation,
|
||||
text(error.path),
|
||||
error.systemCode,
|
||||
{ cause: error },
|
||||
context,
|
||||
);
|
||||
if (error instanceof AnalysisArtifactChangedError)
|
||||
return new AnalysisArtifactChangedError(
|
||||
error.operation,
|
||||
text(error.path),
|
||||
text(error.reason),
|
||||
{ cause: error },
|
||||
context,
|
||||
);
|
||||
if (error instanceof AnalysisInputError)
|
||||
return new AnalysisInputError(
|
||||
error.operation,
|
||||
{ cause: error },
|
||||
context,
|
||||
error.issues.map((issue) => ({
|
||||
...issue,
|
||||
// Unknown-argument paths contain literal field names, including names
|
||||
@@ -104,16 +139,18 @@ export const redactExplicitFailure = (
|
||||
})),
|
||||
);
|
||||
if (error instanceof AnalysisOutputError)
|
||||
return new AnalysisOutputError(error.operation, text(error.reason), {
|
||||
cause: error,
|
||||
});
|
||||
return new AnalysisOutputError(
|
||||
error.operation,
|
||||
text(error.reason),
|
||||
context,
|
||||
);
|
||||
if (error instanceof AnalysisCapabilityUnavailableError)
|
||||
return new AnalysisCapabilityUnavailableError(
|
||||
error.providerId,
|
||||
error.operation,
|
||||
text(error.reason),
|
||||
{
|
||||
cause: error,
|
||||
...context,
|
||||
...(error.userMessage === undefined
|
||||
? {}
|
||||
: { userMessage: text(error.userMessage) }),
|
||||
@@ -126,19 +163,10 @@ export const redactExplicitFailure = (
|
||||
text(error.reason),
|
||||
error.reportedLimits === null ? null : diagnostics(error.reportedLimits),
|
||||
{
|
||||
cause: error,
|
||||
...context,
|
||||
...(error.remediationAction === undefined
|
||||
? {}
|
||||
: { remediationAction: text(error.remediationAction) }),
|
||||
...(error.capturedOutput === undefined
|
||||
? {}
|
||||
: {
|
||||
capturedOutput: {
|
||||
stdout: text(error.capturedOutput.stdout),
|
||||
stderr: text(error.capturedOutput.stderr),
|
||||
truncated: error.capturedOutput.truncated,
|
||||
},
|
||||
}),
|
||||
},
|
||||
);
|
||||
if (error instanceof ProviderCleanupError)
|
||||
@@ -149,11 +177,6 @@ export const redactExplicitFailure = (
|
||||
{ operation: error.operation, cause: error },
|
||||
);
|
||||
if (error instanceof ProviderAdapterError)
|
||||
return new ProviderAdapterError(error.providerId, error.operation, {
|
||||
cause: error,
|
||||
...(error.diagnostics === undefined
|
||||
? {}
|
||||
: { diagnostics: diagnostics(error.diagnostics) }),
|
||||
});
|
||||
return new ProviderAdapterError(error.providerId, error.operation, context);
|
||||
return error;
|
||||
};
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import type { JsonValue } from "./jsonValue.js";
|
||||
import {
|
||||
AnalysisError,
|
||||
type AnalysisErrorOptions,
|
||||
@@ -7,14 +6,12 @@ import {
|
||||
/** A provider adapter failed outside its more precise typed variants. */
|
||||
export interface ProviderAdapterErrorOptions extends AnalysisErrorOptions {
|
||||
readonly userMessage?: string;
|
||||
readonly diagnostics?: Readonly<Record<string, JsonValue>>;
|
||||
}
|
||||
|
||||
/** A provider adapter failed outside its more precise typed variants. */
|
||||
export class ProviderAdapterError extends AnalysisError {
|
||||
readonly _tag = "ProviderAdapterError";
|
||||
override readonly userMessage: string | undefined;
|
||||
readonly diagnostics: Readonly<Record<string, JsonValue>> | undefined;
|
||||
|
||||
constructor(
|
||||
readonly providerId: string,
|
||||
@@ -23,9 +20,5 @@ export class ProviderAdapterError extends AnalysisError {
|
||||
) {
|
||||
super(`Provider ${providerId} adapter failed during ${operation}`, options);
|
||||
this.userMessage = options.userMessage;
|
||||
this.diagnostics =
|
||||
options.diagnostics === undefined
|
||||
? undefined
|
||||
: structuredClone(options.diagnostics);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user