Skip to content

Commit

Permalink
Merge pull request #192 from JarvusInnovations/fix/issue-187
Browse files Browse the repository at this point in the history
Fix #187: Post-run should exit cleanly when log files are missing
  • Loading branch information
jmealo authored Mar 28, 2024
2 parents e317a3e + 15f2d30 commit 59e89a8
Showing 1 changed file with 35 additions and 8 deletions.
43 changes: 35 additions & 8 deletions post-run.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ const stderrPath = path.join(cwd, `${pid}.err`)

const shouldLog = logOutputIf === 'true' || logOutputIf === reason || (logOutputIf === 'failure' && (reason === 'exit-early' || reason === 'timeout'))

core.debug({ reason, pid, stderrPath, stdoutPath, stdout, stderr, inputs, shouldLog })

if (shouldLog) {
streamLogs()
} else {
process.exit(0)
if (core.isDebug()) {
core.debug(`stdout: ${stdout}`)
core.debug(`stderr: ${stderr}`)
core.debug(`stdoutPath: ${stdoutPath}`)
core.debug(`stderrPath: ${stderrPath}`)
core.debug(`shouldLog: ${shouldLog}`)
core.debug(`logOutput: ${logOutput}`)
core.debug(`logOutputResume: ${logOutputResume}`)
core.debug(`logOutputIf: ${logOutputIf}`)
core.debug(`workingDirectory: ${workingDirectory}`)
core.debug(`pid: ${pid}`)
core.debug(`reason: ${reason}`)
core.debug(`cwd: ${cwd}`)
}

function streamLog(path, start) {
Expand All @@ -39,7 +46,11 @@ async function streamLogs() {
const truncated = start > 0
await core.group(`${logOutputResume.stdout ? 'Truncated ' : ''}Output:`, async () => {
if (truncated) console.log(`Truncated ${start} bytes of tailed stdout output`)
await streamLog(stdoutPath, start)
try {
await streamLog(stdoutPath, start)
} catch(err) {
console.error('Error streaming stdout:', err)
}
})
}

Expand All @@ -48,7 +59,23 @@ async function streamLogs() {
const truncated = start > 0
await core.group(`${logOutputResume.stderr ? 'Truncated ' : ''}Error Output:`, async () => {
if (truncated) console.log(`Truncated ${start} bytes of tailed stderr output`)
await streamLog(stderrPath, start)
try {
await streamLog(stderrPath, start)
} catch(err) {
console.error('Error streaming stderr:', err)
}
})
}
}

(async() => {
try {
if (shouldLog) {
await streamLogs()
}
} catch(err) {
console.error('Error streaming logs:', err)
} finally {
process.exit(0)
}
})();

0 comments on commit 59e89a8

Please sign in to comment.