Skip to content

Commit

Permalink
Merge pull request #484 from chrisfilo/enh/better_error_reporting
Browse files Browse the repository at this point in the history
Raise an error if fs.open fails
  • Loading branch information
chrisgorgo authored Jul 7, 2018
2 parents 73d38b4 + 4c6c5a4 commit 1a91b2a
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions utils/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,19 @@ function readNiftiHeader (file, callback) {
callback(handleGunzipError(buffer, file));
});

fs.open(file.path, 'r', function(status, fd) {
fs.read(fd, buffer, 0, bytesRead, 0, function() {
if (file.name.endsWith('.nii')) {
callback(parseNIfTIHeader(buffer, file));
} else {
decompressStream.write(buffer);
}
});
fs.open(file.path, 'r', function(err, fd) {
if (err){
callback({error: new Issue({code: 44, file: file})});
return;
} else {
fs.read(fd, buffer, 0, bytesRead, 0, function () {
if (file.name.endsWith('.nii')) {
callback(parseNIfTIHeader(buffer, file));
} else {
decompressStream.write(buffer);
}
});
}
});
});
} else {
Expand Down

0 comments on commit 1a91b2a

Please sign in to comment.