Skip to content

Commit 8ed9e6a

Browse files
Jami CogswellJami Cogswell
authored andcommitted
Log autofix stdout/stderr to the extension logs
1 parent 561cd6c commit 8ed9e6a

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

extensions/ql-vscode/src/variant-analysis/view-autofixes.ts

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,45 @@ function execAutofix(
753753
if (showCommand) {
754754
void extLogger.log(`Spawning '${bin} ${args.join(" ")}' in ${cwd}`);
755755
}
756-
const p = spawn(bin, args, { stdio: [0, 1, 2], ...options });
756+
757+
let stdoutBuffer = "";
758+
let stderrBuffer = "";
759+
760+
const p = spawn(bin, args, {
761+
stdio: ["ignore", "pipe", "pipe"],
762+
...options,
763+
});
764+
765+
// Listen for stdout
766+
p.stdout?.on("data", (data) => {
767+
stdoutBuffer += data.toString();
768+
});
769+
770+
// Listen for stderr
771+
p.stderr?.on("data", (data) => {
772+
stderrBuffer += data.toString();
773+
});
774+
775+
// Listen for errors
757776
p.on("error", reject);
758-
p.on("exit", (code) => (code === 0 ? resolve() : reject(code)));
777+
778+
// Listen for process exit
779+
p.on("exit", (code) => {
780+
// Log collected output
781+
if (stdoutBuffer.trim()) {
782+
void extLogger.log(`Autofix stdout:\n${stdoutBuffer.trim()}`);
783+
}
784+
785+
if (stderrBuffer.trim()) {
786+
void extLogger.log(`Autofix stderr:\n${stderrBuffer.trim()}`);
787+
}
788+
789+
if (code === 0) {
790+
resolve();
791+
} else {
792+
reject(new Error(`Autofix process exited with code ${code}.`));
793+
}
794+
});
759795
} catch (e) {
760796
reject(e);
761797
}

0 commit comments

Comments
 (0)