Skip to content

Commit 7028b23

Browse files
committed
Updates execShellScript to check for errors
1 parent 016291a commit 7028b23

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

server/src/util/sh.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ export function execShellScript(body: string): Promise<string> {
1010
return new Promise((resolve, reject) => {
1111
let output = ''
1212

13-
process.stdout.on('data', buffer => {
14-
output += buffer
15-
})
16-
17-
process.on('close', returnCode => {
13+
const handleClose = (returnCode: number | Error) => {
1814
if (returnCode === 0) {
1915
resolve(output)
2016
} else {
2117
reject(`Failed to execute ${body}`)
2218
}
19+
}
20+
21+
process.stdout.on('data', buffer => {
22+
output += buffer
2323
})
24+
25+
process.on('close', handleClose)
26+
process.on('error', handleClose)
2427
})
2528
}
2629

0 commit comments

Comments
 (0)