@@ -22,39 +22,32 @@ const SIGNAL_NAMES: Readonly<Record<number, string>> = {
2222}
2323
2424/**
25- * `Process exited with code N`, naming the signal behind a code above 128. A killed process often
26- * printed only a warning first, and that warning must not read as the reason it failed; SIGKILL
27- * (137) is usually the out-of-memory killer.
25+ * `Process exited with code N`, naming the signal a code above 128 stands for. A process a signal
26+ * killed often printed only a warning first, so the code must be visible beside whatever it
27+ * printed. The code alone cannot prove a kill (a program may exit 137 itself), so it is described
28+ * as the signal's code; SIGKILL's (137) usually means the out-of-memory killer.
2829 */
2930export function describeProcessExit ( exitCode : number ) : string {
30- const described = `Process exited with code ${ exitCode } `
31- const signal = killingSignal ( exitCode )
32- if ( signal === undefined ) return described
33- const name = SIGNAL_NAMES [ signal ] ?? `signal ${ signal } `
34- return `${ described } (killed by ${ name } ${ signal === 9 ? ', usually out of memory' : '' } )`
31+ const note = signalCodeNote ( exitCode )
32+ return `Process exited with code ${ exitCode } ${ note ? ` (${ note } )` : '' } `
3533}
3634
37- /** The signal a shell's `128 + n` exit code reports, if the code is one. */
38- function killingSignal ( exitCode : number ) : number | undefined {
39- return exitCode > 128 && exitCode <= 128 + 64 ? exitCode - 128 : undefined
35+ /** What a shell's `128 + n` exit code stands for, if the code is one. */
36+ function signalCodeNote ( exitCode : number ) : string | undefined {
37+ if ( exitCode <= 128 || exitCode > 128 + 64 ) return undefined
38+ const signal = exitCode - 128
39+ const name = SIGNAL_NAMES [ signal ] ?? `signal ${ signal } `
40+ return `the exit code of ${ name } ${ signal === 9 ? ', usually out of memory' : '' } `
4041}
4142
4243/**
4344 * Converts a failed code command into a code result, naming the error from the
44- * last error headline of the traceback (stderr, else stdout). A process a signal
45- * killed raised nothing: anything it printed (a warning) is not the cause, so the
46- * signal names the error and the output stays as the traceback .
45+ * last error headline of the traceback (stderr, else stdout). A signal's exit code
46+ * is appended to the value, since a killed process's last printed line (often a
47+ * warning) is not necessarily why it stopped .
4748 */
4849export function processCodeFailure ( result : SandboxCommandResult ) : SandboxCodeResult {
4950 const traceback = result . stderr || result . stdout
50- if ( killingSignal ( result . exitCode ) !== undefined ) {
51- return {
52- text : '' ,
53- stdout : result . stdout ,
54- stderr : result . stderr ,
55- error : { name : 'Error' , value : describeProcessExit ( result . exitCode ) , traceback } ,
56- }
57- }
5851 const headline = traceback
5952 . split ( '\n' )
6053 . reverse ( )
@@ -66,10 +59,13 @@ export function processCodeFailure(result: SandboxCommandResult): SandboxCodeRes
6659 const separator = errorLine ?. indexOf ( ':' ) ?? - 1
6760 const parsedErrorLine = errorLine ?? ''
6861 const name = separator > 0 ? parsedErrorLine . slice ( 0 , separator ) : 'Error'
69- const value =
62+ const headlineValue =
7063 separator > 0
7164 ? parsedErrorLine . slice ( separator + 1 ) . trim ( )
7265 : parsedErrorLine || 'Execution failed'
66+ const value = signalCodeNote ( result . exitCode )
67+ ? `${ headlineValue } [${ describeProcessExit ( result . exitCode ) } ]`
68+ : headlineValue
7369 return {
7470 text : '' ,
7571 stdout : result . stdout ,
0 commit comments