balena-cli/lib/errors.coffee

41 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2014-12-22 16:47:12 +00:00
_ = require('lodash')
os = require('os')
2014-12-22 16:47:12 +00:00
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 16:47:12 +00: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}")
else if error.code is 'EACCES' or error.code is 'EPERM'
message = 'You don\'t have enough privileges to run this operation.\n'
if os.platform() is 'win32'
message += 'Run a new Command Prompt as administrator and try running this command again.'
else
message += 'Try running this command again prefixing it with `sudo`.'
console.error(message)
2015-01-20 19:09:26 +00:00
2015-03-10 17:56:55 +00:00
else if error.code is 'ENOGIT'
console.error '''
Git is not installed on this system.
Head over to http://git-scm.com to install it and run this command again.
'''
else if error.message?
console.error(error.message)
2014-12-22 16:47:12 +00:00
2015-01-06 16:46:31 +00:00
if _.isNumber(error.exitCode)
errorCode = error.exitCode
2014-12-22 16:47:12 +00:00
else
errorCode = 1
process.exit(errorCode) if exit