Do not instantiate errors at module load time

This prevents the right stack trace from being captured.
This commit is contained in:
Eric Mc Sween
2020-09-03 15:34:19 -04:00
parent 1708e29faf
commit c8371a8ea7

View File

@@ -22,11 +22,6 @@ let containerMonitorTimeout
let containerMonitorInterval let containerMonitorInterval
module.exports = DockerRunner = { module.exports = DockerRunner = {
ERR_NOT_DIRECTORY: new Error('not a directory'),
ERR_TERMINATED: new Error('terminated'),
ERR_EXITED: new Error('exited'),
ERR_TIMED_OUT: new Error('container timed out'),
run( run(
projectId, projectId,
command, command,
@@ -190,13 +185,13 @@ module.exports = DockerRunner = {
} }
if (exitCode === 137) { if (exitCode === 137) {
// exit status from kill -9 // exit status from kill -9
err = DockerRunner.ERR_TERMINATED err = new Error('terminated')
err.terminated = true err.terminated = true
return callback(err) return callback(err)
} }
if (exitCode === 1) { if (exitCode === 1) {
// exit status from chktex // exit status from chktex
err = DockerRunner.ERR_EXITED err = new Error('exited')
err.code = exitCode err.code = exitCode
return callback(err) return callback(err)
} }
@@ -353,7 +348,7 @@ module.exports = DockerRunner = {
return cb(err) return cb(err)
} }
if (!stats.isDirectory()) { if (!stats.isDirectory()) {
return cb(DockerRunner.ERR_NOT_DIRECTORY) return cb(new Error('not a directory'))
} }
cb() cb()
}) })
@@ -501,7 +496,7 @@ module.exports = DockerRunner = {
} }
if (timedOut) { if (timedOut) {
logger.log({ containerId }, 'docker container timed out') logger.log({ containerId }, 'docker container timed out')
error = DockerRunner.ERR_TIMED_OUT error = new Error('container timed out')
error.timedout = true error.timedout = true
callback(error) callback(error)
} else { } else {