Skip to content

Commit 594fa53

Browse files
committed
[changed] added reach error
1 parent 5e1949f commit 594fa53

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/util/reach.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
'use strict';
21
let { forEach } = require('property-expr')
32
, { has } = require('./_');
43

54
let trim = part => part.substr(0, part.length - 1).substr(1)
65

76
module.exports = function (obj, path, value, context) {
7+
let parent, lastPart;
8+
89
// if only one "value" arg then use it for both
910
context = context || value;
1011

11-
let parent, lastPart;
12-
1312
forEach(path, (_part, isBracket, isArray) => {
1413
let part = isBracket ? trim(_part) : _part;
1514

@@ -21,18 +20,19 @@ module.exports = function (obj, path, value, context) {
2120
if (!isArray) {
2221
obj = obj._resolve(context, parent);
2322

24-
if (!has(obj, 'fields'))
23+
if (!has(obj, 'fields') || !has(obj.fields, part))
2524
throw new Error(
2625
`The schema does not contain the path: ${path}. ` +
2726
`(failed at: ${lastPart} which is a type: "${obj._type}") `
2827
)
2928

3029
obj = obj.fields[part]
30+
3131
parent = value;
3232
value = value && value[part]
3333
lastPart = isBracket ? '[' + _part + ']' : '.' + _part
3434
}
3535
})
3636

37-
return obj._resolve(parent)
37+
return obj && obj._resolve(parent)
3838
}

0 commit comments

Comments
 (0)