Rename error code to error exit code

This commit is contained in:
Juan Cruz Viotti 2015-01-06 13:46:31 -03:00
parent ac00a96728
commit e9caca8c24
4 changed files with 22 additions and 22 deletions

View File

@ -47,9 +47,9 @@ exports.add = permissions.user (params) ->
# 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: #{params.path}"
error.message = "File is a directory: #{error.path}"
if error.code is 'ENOENT'
error = new Error("File not found: #{params.path}")
error = new Error("File not found: #{error.path}")
errors.handle(error)

View File

@ -10,8 +10,8 @@ exports.handle = (error, exit = true) ->
if error.message?
log.error(error.message)
if _.isNumber(error.code)
errorCode = error.code
if _.isNumber(error.exitCode)
errorCode = error.exitCode
else
errorCode = 1

View File

@ -48,9 +48,9 @@ describe 'Errors:', ->
checkProcessExitOption error, false, (processExitStub) ->
expect(processExitStub).to.not.have.been.called
it 'should handle a custom error code from the error instance', ->
it 'should handle a custom error exit code from the error instance', ->
error = new Error()
error.code = 123
error.exitCode = 123
checkProcessExitOption error, true, (processExitStub) ->
expect(processExitStub).to.have.been.calledWith(123)

View File

@ -13,8 +13,8 @@ exports.NotFound = class NotFound extends TypedError
constructor: (name) ->
@message = "Couldn't find #{name}"
# Error code
code: 1
# Error exit code
exitCode: 1
exports.InvalidConfigFile = class InvalidConfigFile extends TypedError
@ -29,8 +29,8 @@ exports.InvalidConfigFile = class InvalidConfigFile extends TypedError
constructor: (file) ->
@message = "Invalid configuration file: #{file}"
# Error code
code: 1
# Error exit code
exitCode: 1
exports.InvalidCredentials = class InvalidCredentials extends TypedError
@ -43,8 +43,8 @@ exports.InvalidCredentials = class InvalidCredentials extends TypedError
constructor: ->
@message = 'Invalid credentials'
# Error code
code: 1
# Error exit code
exitCode: 1
exports.InvalidKey = class InvalidKey extends TypedError
@ -57,8 +57,8 @@ exports.InvalidKey = class InvalidKey extends TypedError
constructor: ->
@message = 'Invalid key'
# Error code
code: 1
# Error exit code
exitCode: 1
exports.InvalidPath = class InvalidPath extends TypedError
@ -73,8 +73,8 @@ exports.InvalidPath = class InvalidPath extends TypedError
constructor: (path) ->
@message = "Invalid path: #{path}"
# Error code
code: 1
# Error exit code
exitCode: 1
exports.DirectoryDoesntExist = class DirectoryDoesntExist extends TypedError
@ -89,8 +89,8 @@ exports.DirectoryDoesntExist = class DirectoryDoesntExist extends TypedError
constructor: (directory) ->
@message = "Directory doesn't exist: #{directory}"
# Error code
code: 1
# Error exit code
exitCode: 1
exports.NotAny = class NotAny extends TypedError
@ -105,8 +105,8 @@ exports.NotAny = class NotAny extends TypedError
constructor: (name) ->
@message = "You don't have any #{name}"
# Error code
code: 0
# Error exit code
exitCode: 0
exports.FileNotFound = class FileNotFound extends TypedError
@ -121,5 +121,5 @@ exports.FileNotFound = class FileNotFound extends TypedError
constructor: (filename) ->
@message = "File not found: #{filename}"
# Error code
code: 1
# Error exit code
exitCode: 1