Skip to content

Commit fa1892b

Browse files
authored
Merge pull request #401 from SetCodesToFire/dir-check
Add directory existence check
2 parents 37924a1 + 56cf041 commit fa1892b

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

tests/bids.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,13 @@ var suite = describe('BIDS example datasets ', function() {
151151
isdone();
152152
});
153153
});
154+
155+
// test for directory path not existing
156+
it('checks for non-existing directory', function (isdone) {
157+
var options = {ignoreNiftiHeaders: true};
158+
validate.BIDS("path", options, function (issues) {
159+
assertErrorCode(issues.errors, '68');
160+
});
161+
isdone();
162+
});
154163
});

utils/issues/list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,5 +341,10 @@ module.exports = {
341341
key: 'NO_VALID_DATA_FOUND_FOR_SUBJECT',
342342
severity: 'error',
343343
reason: 'No BIDS compatible data found for at least one subject.'
344+
},
345+
68: {
346+
key: 'DIRECTORY_DOES_NOT_EXIST',
347+
severity: 'error',
348+
reason: 'Either wrong directory is choosen or there is an error in joining the path.'
344349
}
345350
};

validators/bids.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ BIDS = {
3131
* arguments to the callback.
3232
*/
3333
start: function (dir, options, callback) {
34+
if (fs.existsSync(dir)) {
3435
var self = BIDS;
3536
utils.options.parse(options, function (issues, options) {
3637
if (issues && issues.length > 0) {
@@ -60,6 +61,18 @@ BIDS = {
6061
});
6162
}
6263
});
64+
}else{
65+
var filename = path.basename(dir);
66+
var issue = new Issue({
67+
code: 68,
68+
file: {
69+
name: filename,
70+
path: path.join('.', filename),
71+
relativePath: path.join('', filename)
72+
}
73+
});
74+
return issue;
75+
}
6376
},
6477

6578
/*

0 commit comments

Comments
 (0)