balena-cli/lib/errors.coffee

39 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2016-01-04 03:58:51 +00:00
###
2017-06-14 21:20:15 +00:00
Copyright 2016-2017 Resin.io
2016-01-04 03:58:51 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
###
chalk = require('chalk')
errors = require('resin-cli-errors')
patterns = require('./utils/patterns')
2017-03-17 17:37:07 +00:00
Raven = require('raven')
Promise = require('bluebird')
captureException = Promise.promisify(Raven.captureException.bind(Raven))
2014-12-22 16:47:12 +00:00
exports.handle = (error) ->
message = errors.interpret(error)
return if not message?
2014-12-22 16:47:12 +00:00
if process.env.DEBUG
message = error.stack
patterns.printErrorMessage(message)
2017-03-17 17:37:07 +00:00
captureException(error)
.timeout(1000)
.catch(-> # Ignore any errors (from error logging, or timeouts)
).finally ->
process.exit(error.exitCode or 1)