Skip to content

Commit 1a91b2a

Browse files
authored
Merge pull request #484 from chrisfilo/enh/better_error_reporting
Raise an error if fs.open fails
2 parents 73d38b4 + 4c6c5a4 commit 1a91b2a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

utils/files.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,19 @@ function readNiftiHeader (file, callback) {
248248
callback(handleGunzipError(buffer, file));
249249
});
250250

251-
fs.open(file.path, 'r', function(status, fd) {
252-
fs.read(fd, buffer, 0, bytesRead, 0, function() {
253-
if (file.name.endsWith('.nii')) {
254-
callback(parseNIfTIHeader(buffer, file));
255-
} else {
256-
decompressStream.write(buffer);
257-
}
258-
});
251+
fs.open(file.path, 'r', function(err, fd) {
252+
if (err){
253+
callback({error: new Issue({code: 44, file: file})});
254+
return;
255+
} else {
256+
fs.read(fd, buffer, 0, bytesRead, 0, function () {
257+
if (file.name.endsWith('.nii')) {
258+
callback(parseNIfTIHeader(buffer, file));
259+
} else {
260+
decompressStream.write(buffer);
261+
}
262+
});
263+
}
259264
});
260265
});
261266
} else {

0 commit comments

Comments
 (0)