fix(android): report startup and selector failure causes
This commit is contained in:
@@ -109,6 +109,11 @@ export class JadxMcpTransport implements Transport {
|
||||
return this.#supervisor?.snapshot().stderr.text ?? "";
|
||||
}
|
||||
|
||||
/** Whether the retained startup/operation diagnostics lost bytes. */
|
||||
diagnosticsTruncated(): boolean {
|
||||
return this.#supervisor?.snapshot().diagnosticTruncated ?? false;
|
||||
}
|
||||
|
||||
/** Preserve the failed protocol/resource constraint after the SDK closes requests. */
|
||||
failureReason(): string | null {
|
||||
return this.#failure;
|
||||
|
||||
@@ -4,6 +4,12 @@ import { jsonValueSchema } from "../domain/jsonValue.js";
|
||||
import type { AndroidOperation } from "../domain/android/androidAnalysis.js";
|
||||
|
||||
const count = z.number().int().nonnegative();
|
||||
/** Selector failures authored by REA's bridge, separate from arbitrary engine errors. */
|
||||
export const jadxInputFailureSchema = z.strictObject({
|
||||
kind: z.literal("invalid-input"),
|
||||
field: z.enum(["class_name", "method_name", "overload_index"]),
|
||||
message: z.string().min(1),
|
||||
});
|
||||
/** Values observed inside the exact JVM producing the analysis. */
|
||||
export const jadxRuntimeSchema = z.object({
|
||||
engine_reported_version: z.string().min(1),
|
||||
|
||||
@@ -73,6 +73,24 @@ const executionError = (context: {
|
||||
"JADX response violated the pinned upstream protocol",
|
||||
{ cause },
|
||||
);
|
||||
if (session !== undefined && !session.initialized()) {
|
||||
const stderr = session.transport.diagnostics();
|
||||
const reason = `Java could not start REA's Android bridge using ${session.transport.options.command}: ${cause instanceof Error ? cause.message : String(cause)}.${stderr.length === 0 ? "" : ` Java diagnostics: ${stderr}`} Select a full JDK including jdk.compiler via JAVA_HOME, or a working java on PATH; verify it with java --list-modules. A JRE cannot compile REA's source bridge. If the JDK works, verify the REA bridge and configured JADX JAR installation.`;
|
||||
return new AnalysisCapabilityUnavailableError(
|
||||
"jadx",
|
||||
request.operation,
|
||||
reason,
|
||||
{
|
||||
cause,
|
||||
userMessage: reason,
|
||||
capturedOutput: {
|
||||
stdout: "",
|
||||
stderr,
|
||||
truncated: session.transport.diagnosticsTruncated(),
|
||||
},
|
||||
},
|
||||
);
|
||||
}
|
||||
return new ProviderAdapterError("jadx", request.operation, {
|
||||
cause,
|
||||
diagnostics: {
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
import type { AndroidRequest } from "../domain/android/androidAnalysis.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
AnalysisInputError,
|
||||
AnalysisOutputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTarget.js";
|
||||
@@ -16,6 +17,7 @@ import { analyzeJadxRequest, type JadxToolPort } from "./JadxAnalysis.js";
|
||||
import { JadxMcpTransport, type JadxLauncher } from "./JadxMcpTransport.js";
|
||||
import {
|
||||
jadxLoadSchema,
|
||||
jadxInputFailureSchema,
|
||||
jadxRuntimeSchema,
|
||||
parseJadxEnvelope,
|
||||
parseJadxJson,
|
||||
@@ -32,6 +34,7 @@ export class JadxSession {
|
||||
readonly transport: JadxMcpTransport;
|
||||
readonly #client = new Client({ name: "rea-android-adapter", version: "1" });
|
||||
#loaded: ReturnType<typeof jadxLoadSchema.parse> | undefined;
|
||||
#connected = false;
|
||||
|
||||
constructor(
|
||||
options: Omit<OwnedProviderProcessSpawnOptions, "runId" | "stdin">,
|
||||
@@ -58,8 +61,10 @@ export class JadxSession {
|
||||
signal.throwIfAborted();
|
||||
this.transport.beginOperation();
|
||||
const raw: JsonValue[] = [];
|
||||
if (this.#loaded === undefined)
|
||||
if (!this.#connected) {
|
||||
await this.#client.connect(this.transport, { timeout: 30_000 });
|
||||
this.#connected = true;
|
||||
}
|
||||
const server = this.#client.getServerVersion();
|
||||
if (
|
||||
server?.name !== JADX_BRIDGE_IDENTITY.name ||
|
||||
@@ -126,6 +131,11 @@ export class JadxSession {
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether the selected Java runtime established the REA bridge protocol. */
|
||||
initialized(): boolean {
|
||||
return this.#connected;
|
||||
}
|
||||
|
||||
/** Join owned cleanup even if SDK connection teardown itself fails. */
|
||||
async close(): Promise<void> {
|
||||
try {
|
||||
@@ -156,7 +166,20 @@ export class JadxSession {
|
||||
input,
|
||||
response: jsonValueSchema.parse(response),
|
||||
});
|
||||
if (envelope.failed)
|
||||
if (envelope.failed) {
|
||||
if (envelope.text.startsWith("{")) {
|
||||
const failure = jadxInputFailureSchema.safeParse(
|
||||
parseJadxJson(envelope.text, request.operation),
|
||||
);
|
||||
if (failure.success)
|
||||
throw new AnalysisInputError(request.operation, undefined, [
|
||||
{
|
||||
path: [failure.data.field],
|
||||
reason: "invalid_value",
|
||||
message: failure.data.message,
|
||||
},
|
||||
]);
|
||||
}
|
||||
throw new ProviderAdapterError("jadx", request.operation, {
|
||||
diagnostics: {
|
||||
upstream_operation: name,
|
||||
@@ -165,6 +188,7 @@ export class JadxSession {
|
||||
target_sha256: target.sha256,
|
||||
},
|
||||
});
|
||||
}
|
||||
return envelope.text;
|
||||
};
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user