balena-cli/lib/errors/errors.coffee

27 lines
638 B
CoffeeScript
Raw Normal View History

2014-12-22 12:47:12 -04:00
_ = require('lodash')
exports.handle = (error, exit = true) ->
return if not error? or error not instanceof Error
if process.env.DEBUG
console.error(error.stack)
2014-12-22 12:47:12 -04:00
else
if error.code is 'EISDIR'
console.error("File is a directory: #{error.path}")
else if error.code is 'ENOENT'
console.error("No such file or directory: #{error.path}")
2015-01-20 15:09:26 -04:00
else if error.code is 'EACCES'
console.error('You don\'t have enough privileges to run this operation.')
else if error.message?
console.error(error.message)
2014-12-22 12:47:12 -04:00
2015-01-06 13:46:31 -03:00
if _.isNumber(error.exitCode)
errorCode = error.exitCode
2014-12-22 12:47:12 -04:00
else
errorCode = 1
process.exit(errorCode) if exit