2014-12-22 16:47:12 +00:00
|
|
|
_ = require('lodash')
|
2015-01-29 14:39:12 +00:00
|
|
|
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
|
2015-01-15 14:36:43 +00:00
|
|
|
console.error(error.stack)
|
2014-12-22 16:47:12 +00:00
|
|
|
else
|
2015-01-06 16:54:40 +00:00
|
|
|
if error.code is 'EISDIR'
|
2015-01-15 14:36:43 +00:00
|
|
|
console.error("File is a directory: #{error.path}")
|
2015-01-06 16:54:40 +00:00
|
|
|
|
|
|
|
else if error.code is 'ENOENT'
|
2015-01-15 14:36:43 +00:00
|
|
|
console.error("No such file or directory: #{error.path}")
|
2015-01-06 16:54:40 +00:00
|
|
|
|
2015-01-28 19:45:30 +00:00
|
|
|
else if error.code is 'EACCES' or error.code is 'EPERM'
|
2015-01-29 14:39:12 +00:00
|
|
|
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.
|
|
|
|
'''
|
|
|
|
|
2015-01-06 16:54:40 +00:00
|
|
|
else if error.message?
|
2015-01-15 14:36:43 +00:00
|
|
|
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
|