Skip to content

Commit

Permalink
Merge pull request #548 from michaelbpaulson/error-null-bug
Browse files Browse the repository at this point in the history
Error null bug
  • Loading branch information
ThePrimeagen committed Sep 14, 2015
2 parents ab72597 + bf55adc commit e318ed7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/get/onValueType.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ module.exports = function onValueType(
// If there is an error, then report it as a value if
else if (currType === $error) {
if (fromReference) {
requestedPath.push(null);
requestedPath[depth] = null;
}
if (isJSONG || model._treatErrorsAsValues) {
onValue(model, node, seed, depth, outerResults, requestedPath,
Expand All @@ -65,7 +65,7 @@ module.exports = function onValueType(
// Report the value
else {
if (fromReference) {
requestedPath[depth + 1] = null;
requestedPath[depth] = null;
}

if (!requiresMaterializedToReport ||
Expand Down
29 changes: 28 additions & 1 deletion test/get-core/errors.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ describe('Errors', function() {
reference: ref(['to', 'error']),
to: {
error: error('Oops!'),
expired: expired
expired: expired,
title: 'Hello World'
},
list: {
0: ref(['to']),
1: ref(['to', 'error'])
}
};
};

Expand Down Expand Up @@ -81,5 +86,27 @@ describe('Errors', function() {
cache: errorCache
});
});

it('should report both values and errors when error is less length than value path.', function() {
getCoreRunner({
input: [
['list', {to: 1}, 'title']
],
output: {
json: {
list: {
0: {
title: 'Hello World'
}
}
}
},
errors: [{
path: ['list', 1, null],
value: 'Oops!'
}],
cache: errorCache
});
});
});

21 changes: 21 additions & 0 deletions test/get-core/references.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('References', function() {
circular: ref(['circular', 'next']),
to: {
reference: ref(['to']),
toValue: ref(['to', 'title']),
title: 'Title'
},
toShort: 'Short'
Expand Down Expand Up @@ -57,5 +58,25 @@ describe('References', function() {
});
});

it('should ensure that values are followed correctly when through references and previous paths have longer lengths to litter the requested path.', function() {
getCoreRunner({
input: [
['to', ['reference', 'toValue'], 'title'],
],
output: {
json: {
to: {
reference: {
title: 'Title'
},
toValue: 'Title'
}
}
},
cache: referenceCache
});
});


});

0 comments on commit e318ed7

Please sign in to comment.