-
Notifications
You must be signed in to change notification settings - Fork 23
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
Only append highlight to Exception#to_s, not #message #10
Conversation
I'm sorry but I cannot get your point.
Sorry to hear that. Could you explain the reason? One of the original motivations of this gem is to reduce confusion having to guess what part of the expression is wrong when reading an error log in an application monitoring service like Sentry. See https://bugs.ruby-lang.org/issues/17930#note-1 . So, I suppose this gem to be useful in production rather than on CI.
I understand this problem. IMO, it is not a good practice for a test to exactly check an error message, but I know that there are actually lots of tests that do that. How about disabling error_highlight on CI for a while, and fixing such tests gradually?
I'm unsure about your idea. A highlighted snippet should be printed to stderr when the ruby interpreter fails, as follows:
The interpreter uses BTW, this approach of this gem (extending |
Probably my bad, I'll try to be clearer.
No need to be sorry. Same reason we already disable
Agreed, and I already started rewriting these tests to use There's just one case where it's a bit tricky, e.g.: Rails.logger.error("blah blah error=#{exception.message} some_id=#{some_id}") In this case the error message becoming multiline is a bit problematic for us.
Ah I didn't know that. Maybe
Maybe Ruby could define both How does that sound? Also is my case a bit clearer now? |
Ah performance. They indeed bring some overhead.
Just for the record: According to the following micro benchmark, the ruby interpreter seems to take about < 0.1 sec., error_highlight does 0.5 sec., and did_you_mean does 3.4 sec. (But the performance of error_highlight depends on the length of the whole source code.)
Anyway, I agree that disabling them may be reasonable for a very high-intensity service.
Yeah, thanks!
As you may know, there is such a message in the core, regardless of did_you_mean and error_highlight.
It is unfortunately a wrong assumption that
It makes sense to me. If the ruby interpreter provides a better extension API to add an auxiliary information into an error log, I will be happy to integrate error_highlight by using it. If we assume that the first line of any error message is self-contained, a simpler alternative idea is to provide
FYI: There is already https://docs.ruby-lang.org/en/3.0.0/Exception.html#method-i-full_message
Yes, thank you for the explanation! |
Yeah, but as you point, it's heavily dependent on the data being scanned. I've seen
Ok, so I suppose I should open a ticket upstream. I'm just really unsure what such API look like. |
Here's another use case to upvote When writing CLI executables, I usually rescue from all exceptions and print only one line with (until now) the Unfortunately, with the otherwise very useful error_highlight gem, a failing run now looks like so: (As a side note: This is not a typical error message, it's just the easiest way to pull an example since I'm revamping this tool. A more typical one would be "runway 16L undeclared for airfield LFNT".) Adding Update: As a workaround, |
@svoop I am afraid if I understand your problem correctly. Could you elaborate your situation? Do you want for your program to print:
in the situation you said? I don't think the message is friendly for an end user, with or without the suggestion of error_highlight. My practice is to show an unexpected exception as "internal error" or something, like this.
If it is printed as "Internal Error", error_highlight suggestion does not matter much, IMO.
Currently, error_highlight modifies only NameError's message. So if you are raising the message with your own exception class rather than NameError, error_highlight should not modify your error message. If it does, it is a bug. I would be happy if you could provide reproducible code. I want to extend error_highlight suggestions to other exception classes than NameError, but I know it is dangerous. So I'm now proposing a dedicated API for error_highlight and did_you_mean to add suggestions https://bugs.ruby-lang.org/issues/18438 |
Exactly, something like the
Oh, believe me, it is. 😄 This is a parser (CLI tool) which every 28 days (when new aeronautical documentation sets are published) may have to be adapted to structural changes upstream. So the end user for these error messages is a developer and it is meaningful enough to decide whether you have to act immediately and tackle the problem, since these publications concern air traffic safety and are time-sensitive. The parser features postmortem drilldown to the conflicting code using |
Thank you for your reply!
Okay I see. But then, I'm not sure why a few lines of error_highlight would be a big deal. Anyway, I think https://bugs.ruby-lang.org/issues/18438 will solve the issue. But we need to wait for Ruby 3.2 at the earliest. For Ruby 3.1, you may want to use
Note that other exception classes don't provide
|
@mame Cool, |
Ruby 3.2 will introduce a new API, https://bugs.ruby-lang.org/issues/18564 Now error_highlight uses the new API if available. I think that solves the problem, so I close this. Thank you! |
Thank you! 🙇 |
I made a PR to showcase the idea, but I suppose there's many alternatives to this PR.
The issue I ran into when testing our app against ruby-head, is that we definitely disable
error_highlight
in production, however on CI it can be useful. But then it breaks lots of assertions about logs and error messages in our test suite.Since ultimately the main goal of
error_highlight
is to show that extended message in things like IRB, etc, I'm thinking it could override#to_s
, but leave#message
untouched.cc @mame what do you think?