Skip to content

Commit

Permalink
chore: throws on non-found variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
maasencioh committed Nov 3, 2016
1 parent 02171c8 commit af856e6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ class NetCDFReader {
variable = variableName;
}

// throws if variable not found
utils.notNetcdf((variable === undefined), 'variable not found');

// go to the offset position
this.buffer.seek(variable.offset);

Expand Down
10 changes: 9 additions & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe('Read file', function () {
record[2].should.be.equal(71408);
});

it('read record variable with object', function () {
it('read non-record variable with object', function () {
const data = fs.readFileSync(pathFiles + 'madis-sao.nc');
var reader = new NetCDFReader(data);
var variables = reader.variables;
Expand All @@ -121,4 +121,12 @@ describe('Read file', function () {
withString[1].should.be.equal(withObject[1]);
withString[2].should.be.equal(withObject[2]);
});

it('read non-existent variable string', function () {
const data = fs.readFileSync(pathFiles + 'madis-sao.nc');
var reader = new NetCDFReader(data);

reader.getDataVariable.bind(reader, 'n\'importe quoi')
.should.throw('Not a valid NetCDF v3.x file: variable not found');
});
});

0 comments on commit af856e6

Please sign in to comment.