-
Notifications
You must be signed in to change notification settings - Fork 367
ValidationError messages include field value #368
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -2112,7 +2112,7 @@ describe('relations', function () { | |
| should.exist(err); | ||
| err.name.should.equal('ValidationError'); | ||
| var msg = 'The `Passport` instance is not valid.'; | ||
| msg += ' Details: `name` can\'t be blank.'; | ||
| msg += ' Details: `name: undefined` can\'t be blank.'; | ||
| err.message.should.equal(msg); | ||
| done(); | ||
| }); | ||
|
|
@@ -2569,7 +2569,7 @@ describe('relations', function () { | |
| Person.create({ name: 'Wilma', addresses: addresses }, function(err, p) { | ||
| err.name.should.equal('ValidationError'); | ||
| var expected = 'The `Person` instance is not valid. '; | ||
| expected += 'Details: `addresses` contains invalid item: `work` (`street` can\'t be blank).'; | ||
| expected += 'Details: `addresses: [ { id: \u001b[32m\'home\'\u001b[39m, street: \u001b[32m\'Home Street\'\u001b[39m },\n { id: \u001b[32m\'work\'\u001b[39m, street: \u001b[32m\'\'\u001b[39m } ]` contains invalid item: `work` (`street` can\'t be blank).'; | ||
|
Member
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. This is wrong. Error messages must not include ANSI color escape sequences.
Member
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. Notice how an invalid item in an array is handled: the message contains This patch should build on top of that and print only the invalid item in the message. Example:
Member
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.
On the second thought, that would be a much more involved change, let's leave it for another day. However, you still need to remove colour codes.
Contributor
Author
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. Ok. Why are the color codes getting inserted in the first place? I'm using 'inspect' from node core API. I had never noticed it to print colors before. Is one of the Loopback dependencies monkey patching it to add colors? I decided to use 'inspect' because it limits how deep it will parse the tree. This seemed like desirable behavior which JSON.stringify does not offer.
Member
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.
That's the default behaviour of
Member
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. Apparently
|
||
| err.message.should.equal(expected); | ||
| done(); | ||
| }); | ||
|
|
@@ -2769,7 +2769,7 @@ describe('relations', function () { | |
| err.name.should.equal('ValidationError'); | ||
| err.details.codes.street.should.eql(['presence']); | ||
| var expected = 'The `Address` instance is not valid. '; | ||
| expected += 'Details: `street` can\'t be blank.'; | ||
| expected += 'Details: `street: undefined` can\'t be blank.'; | ||
| err.message.should.equal(expected); | ||
| done(); | ||
| }); | ||
|
|
||
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.
What do you think of this? I noticed we were producing some strange output in the case of nested documents (which have a type of
function). I don't know how to output a sensible output in that case... but I think it's an edge case that can be left for another day.For strings, objects, and undefined/null we now have some pretty clear output.
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.
Handling non-scalar values (objects, arrays, functions) will be always tricky. You can take a look at chai.js which basically prints only top-level keys of the object.
As for function values,
JSON.stringifyremoves them from the output, which solves the problem. On the other hand, it does not handle circular references, which may be a problem.