Implement errors.handle() debug support

This commit is contained in:
Juan Cruz Viotti 2014-12-10 14:12:12 -04:00
parent 890d672671
commit 3717831c38
3 changed files with 20 additions and 3 deletions

View File

@ -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:

View File

@ -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

View File

@ -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', ->