mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-02-20 17:33:18 +00:00
Make errors.handle handle EISDIR and ENOENT
This commit is contained in:
parent
e9caca8c24
commit
af98a89e51
@ -40,16 +40,4 @@ exports.add = permissions.user (params) ->
|
||||
key = key.trim()
|
||||
resin.models.key.create(params.name, key, callback)
|
||||
|
||||
], (error) ->
|
||||
return if not error?
|
||||
|
||||
# TODO: Make handle() check the error type
|
||||
# and accomodate as most as possible to prevent
|
||||
# this types of checks in client code.
|
||||
if error.code is 'EISDIR'
|
||||
error.message = "File is a directory: #{error.path}"
|
||||
|
||||
if error.code is 'ENOENT'
|
||||
error = new Error("File not found: #{error.path}")
|
||||
|
||||
errors.handle(error)
|
||||
], errors.handle
|
||||
|
@ -7,7 +7,13 @@ exports.handle = (error, exit = true) ->
|
||||
if process.env.DEBUG
|
||||
log.error(error.stack)
|
||||
else
|
||||
if error.message?
|
||||
if error.code is 'EISDIR'
|
||||
log.error("File is a directory: #{error.path}")
|
||||
|
||||
else if error.code is 'ENOENT'
|
||||
log.error("No such file or directory: #{error.path}")
|
||||
|
||||
else if error.message?
|
||||
log.error(error.message)
|
||||
|
||||
if _.isNumber(error.exitCode)
|
||||
|
@ -61,3 +61,19 @@ describe 'Errors:', ->
|
||||
expect(logErrorStub).to.have.been.calledOnce
|
||||
expect(logErrorStub).to.have.been.calledWith(error.stack)
|
||||
delete process.env.DEBUG
|
||||
|
||||
it.only 'should handle EISDIR', ->
|
||||
error = new Error()
|
||||
error.code = 'EISDIR'
|
||||
error.path = 'hello'
|
||||
checkProcessExitOption error, false, (processExitStub, logErrorStub) ->
|
||||
expect(logErrorStub).to.have.been.calledOnce
|
||||
expect(logErrorStub).to.have.been.calledWith('File is a directory: hello')
|
||||
|
||||
it.only 'should handle ENOENT', ->
|
||||
error = new Error()
|
||||
error.code = 'ENOENT'
|
||||
error.path = 'hello'
|
||||
checkProcessExitOption error, false, (processExitStub, logErrorStub) ->
|
||||
expect(logErrorStub).to.have.been.calledOnce
|
||||
expect(logErrorStub).to.have.been.calledWith('No such file or directory: hello')
|
||||
|
Loading…
x
Reference in New Issue
Block a user