Skip to content

Commit 3edd1bf

Browse files
committed
Truncate autobuild errors to 10 lines
1 parent 88a0b7a commit 3edd1bf

File tree

6 files changed

+61
-8
lines changed

6 files changed

+61
-8
lines changed

lib/cli-errors.js

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/cli-errors.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli-errors.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,13 @@ function extractFatalErrors(error: string): string | undefined {
109109

110110
function extractAutobuildErrors(error: string): string | undefined {
111111
const pattern = /.*\[autobuild\] \[ERROR\] (.*)/gi;
112-
return (
113-
[...error.matchAll(pattern)].map((match) => match[1]).join("\n") ||
114-
undefined
115-
);
112+
let errorLines = [...error.matchAll(pattern)].map((match) => match[1]);
113+
// Truncate if there are more than 10 matching lines.
114+
if (errorLines.length > 10) {
115+
errorLines = errorLines.slice(0, 10);
116+
errorLines.push("(truncated)");
117+
}
118+
return errorLines.join("\n") || undefined;
116119
}
117120

118121
function ensureEndsInPeriod(text: string): string {

src/codeql.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,34 @@ test("runTool summarizes autobuilder errors", async (t) => {
10021002
);
10031003
});
10041004

1005+
test("runTool truncates long autobuilder errors", async (t) => {
1006+
const stderr = Array.from(
1007+
{ length: 20 },
1008+
(_, i) => `[2019-09-18 12:00:00] [autobuild] [ERROR] line${i + 1}`,
1009+
).join("\n");
1010+
stubToolRunnerConstructor(1, stderr);
1011+
const codeqlObject = await codeql.getCodeQLForTesting();
1012+
sinon.stub(codeqlObject, "getVersion").resolves(makeVersionInfo("2.12.4"));
1013+
sinon.stub(codeqlObject, "resolveExtractor").resolves("/path/to/extractor");
1014+
// safeWhich throws because of the test CodeQL object.
1015+
sinon.stub(safeWhich, "safeWhich").resolves("");
1016+
1017+
await t.throwsAsync(
1018+
async () => await codeqlObject.runAutobuild(Language.java, false),
1019+
{
1020+
instanceOf: CommandInvocationError,
1021+
message:
1022+
"We were unable to automatically build your code. Please provide manual build steps. " +
1023+
"For more information, see " +
1024+
"https://docs.github.com/en/code-security/code-scanning/troubleshooting-code-scanning/automatic-build-failed. " +
1025+
"Encountered the following error: " +
1026+
`${Array.from({ length: 10 }, (_, i) => `line${i + 1}`).join(
1027+
"\n",
1028+
)}\n(truncated)`,
1029+
},
1030+
);
1031+
});
1032+
10051033
test("runTool outputs last line of stderr if fatal error could not be found", async (t) => {
10061034
const cliStderr = "line1\nline2\nline3\nline4\nline5";
10071035
stubToolRunnerConstructor(32, cliStderr);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy