Skip to content

Commit

Permalink
Handle missing part of object
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelOtter committed May 30, 2016
1 parent a4c8e17 commit 2d6fffa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/extract.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,13 @@ function extractArray(data, schema, stacks, hints) {
}
});
result.match = foundMatch;
if (result.value.length === 0 && array.match) {
newStacks.staleKeys.push(array.match);
result = extractArray(data, schema, newStacks);
if (result.value.length === 0) {
if (array.match) {
newStacks.staleKeys.push(array.match);
result = extractArray(data, schema, newStacks);
} else {
throw new util.NotFoundException(data, schema, hints);
}
}
return result;
}
Expand Down
10 changes: 10 additions & 0 deletions test/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,14 @@ describe('basic', function() {
}).to.throw('Could not find');
});

it('should throw exception if part of schema cannot be found', function() {
var schema = {
words: ['String'],
nums: ['Number']
};
expect(function() {
reshaper([1, 2, 3], schema)
}).to.throw('Could not find');
});

});

0 comments on commit 2d6fffa

Please sign in to comment.