-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Format: show backtrace when formatting bug found #4631
Format: show backtrace when formatting bug found #4631
Conversation
It's very useful to maintain autogenerated code. LGTM. |
27bf6bc
to
bf45582
Compare
STDERR.puts | ||
|
||
STDERR.puts ex | ||
ex.backtrace.each do |frame| |
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 think you shoud use ex.inspect_with_backtrace(STDERR)
instead
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.
@bew STDOUT
-> STDERR
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.
true, thanks I'll change it 💤
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.
Thank you!
ping? I really want to merge it. |
@@ -68,7 +68,7 @@ class Crystal::Command | |||
when .invalid_byte_sequence? | |||
error "'#{result.filename}' is not a valid Crystal source file", exit_code: nil | |||
when .bug? | |||
error "there's a bug formatting '#{result.filename}', please report it including the contents of the file: https://github.com/crystal-lang/crystal/issues", exit_code: nil | |||
error "there's a bug formatting '#{result.filename}', to show more information, please run:\n\n $ crystal tool format '#{result.filename}'", exit_code: nil |
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.
Why not show the backtrace for the file here? Why do you tell the user to run format on the individual file?
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.
FormatResult
does not keep an error object currently. I prefer small fix.- It is hard to read multiple backtrace, and each of errors may be not related to others. I expect to report formatter error with this backtrace.
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.
For the multiple-backtrace situation i would expect the formatter to report the first error the same as the single-file mode and then exit. I wonder what the rest of the team think about this but I wouldn't be opposed to storing the error.
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.
For the multiple-backtrace situation i would expect the formatter to report the first error the same as the single-file mode and then exit.
This behavior has a big problem: it makes hard to format all files when formatter bug is found. It should continue to format file as possible.
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.
Why not just print all the backtraces then? Just a simple
Error: couldn't format foo.cr, please report a bug including the contents of it
<inspect_with_backtrace>
Error: couldn't format bar.cr, please report a bug including the contents of it
<inspect_with_backtrace>
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 explained this already: "It is hard to read multiple backtrace", and I worry to open a new issue with unrelated multiple backtraces.
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.
And how does making them run the formatter for each file which is broken help that? This is a kludge at best.
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.
They will see new message "please report a bug including the contents of it" by running formatter for each file, it helps them, and I think my solution is kludge enough.
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 think we need another opinion on this.
end | ||
end | ||
end | ||
|
||
private def couldnt_format(file) | ||
private def couldnt_format(file, ex) | ||
STDERR << "Error:".colorize(:red).toggle(@color) << ", " << | ||
"couldn't format " << file << ", please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues" |
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.
how about
the contents of the file and this backtrace
?
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.
me too...
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.
Reverted for now.
19b2c3d
to
1563f3c
Compare
Resolved conflicts. |
ping. I desire to merge this. |
STDERR << "Error:".colorize(:red).toggle(@color) << ", " << | ||
"couldn't format " << file << ", please report a bug including the contents of it: https://github.com/crystal-lang/crystal/issues" | ||
private def couldnt_format(file, ex = nil) | ||
STDERR << "Error:".colorize(:red).toggle(@color) << ", " |
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.
Why is there a colon and a comma here? I think that's wrong.
Please merge! |
@makenowjust Could you rebase against master? CI is failing in Circle. |
backtrace is useful to fix a bug.
59c72a6
to
0cacfa0
Compare
rebased |
backtrace is useful to fix a bug.