diff --git a/README.md b/README.md index c6f29a21..ff0a4cdb 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/lib/resin/errors/errors.coffee b/lib/resin/errors/errors.coffee index f14da63d..603c9da5 100644 --- a/lib/resin/errors/errors.coffee +++ b/lib/resin/errors/errors.coffee @@ -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 diff --git a/lib/resin/errors/errors.spec.coffee b/lib/resin/errors/errors.spec.coffee index 62e20a20..496ddf03 100644 --- a/lib/resin/errors/errors.spec.coffee +++ b/lib/resin/errors/errors.spec.coffee @@ -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', ->