Skip to content

Commit 626426c

Browse files
paldepindCopilot
andcommitted
JS: Classify native parser crashes consistently after pipe errors
Use the wrapper exit-code classification after IPC failures so a native prefetch crash is reported consistently with malformed responses. Preserve the communication-error fallback when the wrapper is still running. Make the internal-error integration test terminate the native child instead of relying on the legacy parser's stack overflow. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 9f12f7cb-26aa-405b-a1f0-9dcc239778cb
1 parent beb669d commit 626426c

3 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎javascript/extractor/src/com/semmle/ts/extractor/TypeScriptParser.java‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,7 @@ private JsonObject talkToParserWrapper(JsonObject request) {
365365
throw getExceptionFromMalformedResponse(response, e);
366366
}
367367
} catch (IOException e) {
368-
throw new CatastrophicError(
369-
"Could not communicate with TypeScript parser wrapper "
370-
+ "(command: ."
371-
+ parserWrapperCommand
372-
+ ").",
373-
e);
368+
throw getExceptionFromMalformedResponse(response, e);
374369
}
375370
}
376371

@@ -397,6 +392,14 @@ private RuntimeException getExceptionFromMalformedResponse(String response, Exce
397392
} catch (InterruptedException e1) {
398393
Exceptions.ignore(e, "This is for diagnostic purposes only.");
399394
}
395+
if (e instanceof IOException) {
396+
return new CatastrophicError(
397+
"Could not communicate with TypeScript parser wrapper "
398+
+ "(command: ."
399+
+ parserWrapperCommand
400+
+ ").",
401+
e);
402+
}
400403
if (response == null) {
401404
return new CatastrophicError("No response from TypeScript parser wrapper", e);
402405
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const childProcess = require("node:child_process");
2+
const spawn = childProcess.spawn;
3+
childProcess.spawn = function (...args) {
4+
const child = spawn.apply(this, args);
5+
child.kill();
6+
return child;
7+
};
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
def test(codeql, javascript):
2-
codeql.database.create(_assert_failure=True)
1+
import os
2+
3+
4+
def test(codeql, javascript, cwd):
5+
os.environ["NODE_OPTIONS"] = f'--require "{cwd / "fail-native.cjs"}"'
6+
codeql.database.create(source_root="src", _assert_failure=True)

0 commit comments

Comments
 (0)