-
Notifications
You must be signed in to change notification settings - Fork 15.5k
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
Adds better Ruby error messages for TypeErrors by including the field name #4250
Conversation
* TODO: derive field name for repeated fields
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure. |
1 similar comment
Thanks for your pull request. The automated tests will run as soon as one of the admins verifies this change is ok for us to run on our infrastructure. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed, please reply here (e.g.
|
I signed it! |
CLAs look good, thanks! |
Debugging type errors in Ruby is very difficult because of the poor error messages here. What can be done to move this PR along? |
ping @TeBoring |
1 similar comment
ping @TeBoring |
m.repeated_int32.push "hello" | ||
end | ||
assert_equal e.message, "Expected number type for integral field: foo" # TODO |
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 seems to be an error for this line.
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.
Thats correct. As I noted in the writeup, I haven't implemented reporting the field names for repeated types. I wasn't sure how to pull the field name out of the repeated container. I wanted to make sure you all were okay with this approach before trying to figure out how to grab that information.
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.
Alternatively I can punt on repeated fields for now if this is enough of an improvement on a first pass.
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.
Repeated field is tricky. What if this repeated field is assigned to other message and the new field is not called foo?
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.
I couldn't agree more :). Why don't I back out the repeated field stuff for now and we can focus on just the setters for primitives?
Without this change, when there is error, does the place of calling setter show in stack trace? |
@TeBoring Currently and with this change, yes, a TypeError is thrown and the stack trace should emit from that location. |
FMO, the current error message + stack track is already enough for debugging. |
@TeBoring Sorry to hear that. This is particularly a problem not for individual setters, but when using the constructor interface to set a number of fields. When using the constructor you have have no idea which field doesn't currently meet the type expectations. This means literally having to bisect larger structs with many fields to debug, which of the fields is throwing an error. I'll give an example. my_msg = MyMsg.new({
field_one: "2",
field_two: 1,
field_three: {}
}) If all of those fields expect an integer, I'll get a stack track that emits from the construction of MyMsg. In the stack trace there is no information about which field is currently emitting a TypeError. |
@TeBoring Here's a great practical example of the current issue:
With the current error I have no idea which of the fields currently has an issue, as the error raises from line 43, where the constructor is called. |
Currently the TypeErrors thrown by the generated classes do not include the field name in the error description, which can make debugging these issues a matter of bisecting messages until the error is repeatable. Including the name of the field in the TypeErrors thrown by these classes helps immensely with their debug-ability.
I've added extra tests to demonstrate this new behavior, but wanted to get some feedback before tackling the field names for the RepeatedField and Map type containers, neither of which currently hold their field name. If the above approach for primitives seems sane, I'd love some guidance on how to add the field names to those type containers so they can be passed to the type checkers for richer error messages.