-
Notifications
You must be signed in to change notification settings - Fork 566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix errors and improve error messaging #158
Changes from 20 commits
9ab877d
3aada21
313a23c
a11ea07
a3d17ec
7f32410
90345f5
55308c7
3834001
fa4a221
f0d54c4
6ae3445
5daa56a
455b32d
dbf042b
baf7134
7eb7383
2147cc6
23a63e3
aac23f5
9cd8a70
c7f99ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{ | ||
|
||
"a": "{b}", | ||
"b": "{c}", | ||
"c": "{d}", | ||
"d": "{a}" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"a": { | ||
"b": { | ||
"c": "{d}" | ||
"c": "{j}" | ||
} | ||
}, | ||
"d": "{a.b.c}" | ||
} | ||
"j": "{a.b.c}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
{ | ||
"a": { | ||
"b": { | ||
"c": "{d.e.f}" | ||
} | ||
"b": "{c.d.e}" | ||
}, | ||
"d": { | ||
"e": { | ||
"f": "{a.b.c}" | ||
"c": { | ||
"d": { | ||
"e": "{a.b}" | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
{ | ||
"a": { | ||
"b": { | ||
"c": "{d.e.f}" | ||
"c": { | ||
"d": "{e.f.g}" | ||
} | ||
} | ||
}, | ||
"d": { | ||
"e": { | ||
"f": "{g.h}" | ||
"e": { | ||
"f": { | ||
"g": "{h.i}" | ||
} | ||
}, | ||
"g": { | ||
"h": "{a.b.c}" | ||
"h": { | ||
"i": "{a.b.c.d}" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"k": "{l}", | ||
"l": "{m}", | ||
"m": "{l}", | ||
"n": "{k}" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"prop1" : { "value": "test1 value" }, | ||
"prop2" : { "value": "test2 value" }, | ||
"prop3" : { "value": "{prop1.value}" }, | ||
"prop4" : { "value": "{prop3.value}" }, | ||
"prop12" : { "value": "{prop1.value}, {prop2.value} and some extra stuff" }, | ||
"prop124" : { "value": "{prop1.value}, {prop2.value} and {prop4.value}" } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ | |
|
||
var resolveObject = require('../../lib/utils/resolveObject'); | ||
var helpers = require('../__helpers'); | ||
var GroupMessages = require('../../lib/utils/groupMessages'); | ||
|
||
var PROPERTY_REFERENCE_WARNINGS = GroupMessages.GROUP.PropertyReferenceWarnings; | ||
|
||
describe('utils', () => { | ||
describe('resolveObject', () => { | ||
|
@@ -114,26 +117,58 @@ describe('utils', () => { | |
}); | ||
|
||
it('should gracefully handle circular references', () => { | ||
expect( | ||
resolveObject.bind(null, | ||
helpers.fileToJSON(__dirname + '/../__json_files/circular.json') | ||
) | ||
).toThrow('Circular definition: a | d'); | ||
expect( | ||
resolveObject.bind(null, | ||
helpers.fileToJSON(__dirname + '/../__json_files/circular_2.json') | ||
) | ||
).toThrow('Circular definition: a.b.c | d'); | ||
expect( | ||
resolveObject.bind(null, | ||
helpers.fileToJSON(__dirname + '/../__json_files/circular_3.json') | ||
) | ||
).toThrow('Circular definition: a.b.c | d.e.f'); | ||
expect( | ||
resolveObject.bind(null, | ||
helpers.fileToJSON(__dirname + '/../__json_files/circular_4.json') | ||
) | ||
).toThrow('Circular definition: a.b.c | g.h'); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/circular.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(1); | ||
expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_REFERENCE_WARNINGS))).toBe(JSON.stringify([ | ||
'Circular definition cycle: a, b, c, d, a' | ||
])); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/circular_2.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(1); | ||
expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_REFERENCE_WARNINGS))).toBe(JSON.stringify([ | ||
'Circular definition cycle: a.b.c, j, a.b.c' | ||
])); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/circular_3.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(1); | ||
expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_REFERENCE_WARNINGS))).toBe(JSON.stringify([ | ||
'Circular definition cycle: a.b, c.d.e, a.b' | ||
])); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/circular_4.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(1); | ||
expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_REFERENCE_WARNINGS))).toBe(JSON.stringify([ | ||
'Circular definition cycle: a.b.c.d, e.f.g, h.i, a.b.c.d', | ||
])); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/circular_5.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(1); | ||
expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_REFERENCE_WARNINGS))).toBe(JSON.stringify([ | ||
'Circular definition cycle: l, m, l', | ||
])); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
}); | ||
|
||
it('should correctly replace multiple references without reference errors', function() { | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
var obj = resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/not_circular.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(0); | ||
expect(JSON.stringify(obj)).toBe(JSON.stringify({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not about this ticket, but just an occasion to show you one of my perplexities, which is clearly visible here: I am still unsure why the "input" of the tests is stored in a separate file ( |
||
prop1: { value: 'test1 value' }, | ||
prop2: { value: 'test2 value' }, | ||
prop3: { value: 'test1 value' }, | ||
prop4: { value: 'test1 value' }, | ||
prop12: { value: 'test1 value, test2 value and some extra stuff' }, | ||
prop124: { value: 'test1 value, test2 value and test1 value' } | ||
})); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
}); | ||
|
||
describe('ignoreKeys', () => { | ||
|
@@ -238,11 +273,15 @@ describe('utils', () => { | |
}); | ||
|
||
it('should collect multiple reference errors', () => { | ||
expect( | ||
resolveObject.bind(null, | ||
helpers.fileToJSON(__dirname + '/../__json_files/multiple_reference_errors.json') | ||
) | ||
).toThrow('Failed due to 3 errors:'); | ||
GroupMessages.clear(PROPERTY_REFERENCE_WARNINGS); | ||
|
||
resolveObject(helpers.fileToJSON(__dirname + '/../__json_files/multiple_reference_errors.json')); | ||
expect(GroupMessages.count(PROPERTY_REFERENCE_WARNINGS)).toBe(3); | ||
expect(JSON.stringify(GroupMessages.fetchMessages(PROPERTY_REFERENCE_WARNINGS))).toBe(JSON.stringify([ | ||
"Reference doesn't exist: a.b tries to reference b.a, which is not defined", | ||
"Reference doesn't exist: a.c tries to reference b.c, which is not defined", | ||
"Reference doesn't exist: a.d tries to reference d, which is not defined" | ||
])); | ||
}); | ||
|
||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with | ||
* the License. A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions | ||
* and limitations under the License. | ||
*/ | ||
var groupedMessages = {}; | ||
|
||
var GroupMessages = { | ||
GROUP: { | ||
PropertyReferenceWarnings: 'Property Reference Errors', | ||
PropertyValueCollisions: 'Property Value Collisions', | ||
}, | ||
|
||
flush: function (messageGroup) { | ||
var messages = GroupMessages.fetchMessages(messageGroup); | ||
GroupMessages.clear(messageGroup); | ||
return messages; | ||
}, | ||
|
||
add: function (messageGroup, message) { | ||
if(messageGroup) { | ||
if(!groupedMessages[messageGroup]) { | ||
groupedMessages[messageGroup] = []; | ||
} | ||
groupedMessages[messageGroup].push(message); | ||
} | ||
}, | ||
|
||
count: function (messageGroup) { | ||
return groupedMessages[messageGroup] ? groupedMessages[messageGroup].length : 0; | ||
}, | ||
|
||
fetchMessages: function (messageGroup) { | ||
return (messageGroup && groupedMessages[messageGroup]) || []; | ||
}, | ||
|
||
clear: function (messageGroup) { | ||
messageGroup && groupedMessages[messageGroup] && delete groupedMessages[messageGroup]; | ||
} | ||
}; | ||
|
||
module.exports = GroupMessages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the examples!