Skip to content

Commit 899b6d6

Browse files
committed
Improve output logging
- Always log full output (stdout and stderr) on error or with verbosity=all. - Add exit code or signal when process failed.
1 parent a70774f commit 899b6d6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,22 @@ app.post("/", (req, res) => {
185185
}
186186
command += `cd ${match.path} && ${match.command}`
187187
log(`Command running: ${command}`)
188-
exec(command, (error, stdout) => {
189-
if (error) {
190-
stdout && log(stdout, { level: "all" })
191-
error.message && log(error.message, { level: "error" })
192-
} else {
193-
stdout && log(stdout, { level: "all" })
188+
let output = ""
189+
const pc = exec(command)
190+
// Note: stdout and stderr might not arrive in right order, but this can't be fixed as pipes are buffered.
191+
pc.stdout.on("data", (data) => {
192+
output += data
193+
})
194+
pc.stderr.on("data", (data) => {
195+
output += data
196+
})
197+
pc.on("exit", (code, signal) => {
198+
if (code !== null && code === 0) {
199+
output && log(output, { level: "all" })
194200
log("Command succeeded.")
201+
} else {
202+
output && log(output, { level: "error" })
203+
log(`Command failed ${code !== null ? `with exit code ${code}` : `after being terminated by signal ${signal}`}.`, { level: "error" })
195204
}
196205
})
197206
} else {

0 commit comments

Comments
 (0)