mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-24 21:09:54 +00:00
Implement errors.handle() debug support
This commit is contained in:
parent
890d672671
commit
3717831c38
@ -44,6 +44,12 @@ The following command will watch for any changes and will run a linter and the w
|
||||
$ gulp watch
|
||||
```
|
||||
|
||||
If you set `DEBUG` environment variable, errors will print with a stack trace:
|
||||
|
||||
```sh
|
||||
$ DEBUG=true resin ...
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
You can renegerate the documentation with:
|
||||
|
@ -109,8 +109,11 @@ exports.NotAny = class NotAny extends TypedError
|
||||
exports.handle = (error, exit = true) ->
|
||||
return if not error? or error not instanceof Error
|
||||
|
||||
if error.message?
|
||||
log.error(error.message)
|
||||
if process.env.DEBUG
|
||||
log.error(error.stack)
|
||||
else
|
||||
if error.message?
|
||||
log.error(error.message)
|
||||
|
||||
if _.isNumber(error.code)
|
||||
errorCode = error.code
|
||||
|
@ -34,7 +34,7 @@ describe 'Errors:', ->
|
||||
processExitStub = sinon.stub(process, 'exit')
|
||||
logErrorStub = sinon.stub(log, 'error')
|
||||
errors.handle(error, value)
|
||||
expectations(processExitStub)
|
||||
expectations(processExitStub, logErrorStub)
|
||||
processExitStub.restore()
|
||||
logErrorStub.restore()
|
||||
|
||||
@ -54,6 +54,14 @@ describe 'Errors:', ->
|
||||
checkProcessExitOption error, true, (processExitStub) ->
|
||||
expect(processExitStub).to.have.been.calledWith(123)
|
||||
|
||||
it 'should print stack trace if DEBUG is set', ->
|
||||
process.env.DEBUG = true
|
||||
error = new Error()
|
||||
checkProcessExitOption error, false, (processExitStub, logErrorStub) ->
|
||||
expect(logErrorStub).to.have.been.calledOnce
|
||||
expect(logErrorStub).to.have.been.calledWith(error.stack)
|
||||
delete process.env.DEBUG
|
||||
|
||||
describe 'NotFound', ->
|
||||
|
||||
it 'should get a custom message', ->
|
||||
|
Loading…
x
Reference in New Issue
Block a user