Skip to content

Commit

Permalink
Hide exception if config file does not exist (only show error)
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtajina committed Mar 12, 2012
1 parent c402681 commit 58caccd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,11 @@ var parseConfig = function(configFilePath, cliOptions) {
} catch(e) {
if (e.name === 'SyntaxError') {
log.error('Syntax error in config file!');
} else {
log.error('Config file does not exist!');
throw e;
}

throw e;
log.error('Config file does not exist!');
process.exit(1);
}


Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"devDependencies": {
"jasmine-node": ">= 1.0.11",
"jake": ">= 0.2.15",
"mocks": ">= 0.0.1"
"mocks": ">= 0.0.2"
},
"preferGlobal": true,
"repository": {
Expand Down
11 changes: 7 additions & 4 deletions test/unit/config.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe 'config', ->

# create instance of fs mock
mocks = {}
mocks.process = {exit: jasmine.createSpy 'exit'}
mocks.fs = fsMock.create
bin:
sub:
Expand Down Expand Up @@ -222,14 +223,16 @@ describe 'config', ->
expect(config.exclude).toEqual ['/conf/one.js', '/conf/sub/two.js']


it 'should throw and log error if file does not exist', ->
expect(-> e.parseConfig '/conf/not-exist.js').toThrow 'No such file or directory "/conf/not-exist.js"'
it 'should log error and exit if file does not exist', ->
e.parseConfig '/conf/not-exist.js'
expect(consoleSpy).toHaveBeenCalledWith 'error (config): Config file does not exist!'
expect(mocks.process.exit).toHaveBeenCalledWith 1


it 'should throw and log error if it is a directory', ->
expect(-> e.parseConfig '/conf').toThrow 'Illegal operation on directory'
it 'should log error and exit if it is a directory', ->
e.parseConfig '/conf'
expect(consoleSpy).toHaveBeenCalledWith 'error (config): Config file does not exist!'
expect(mocks.process.exit).toHaveBeenCalledWith 1


it 'should throw and log error if invalid file', ->
Expand Down

0 comments on commit 58caccd

Please sign in to comment.