Skip to content
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

Conversation

makenowjust
Copy link
Contributor

backtrace is useful to fix a bug.

@akzhan
Copy link
Contributor

akzhan commented Jun 28, 2017

It's very useful to maintain autogenerated code.

LGTM.

@makenowjust makenowjust force-pushed the fix/crystal-format/show-backtrace-when-bug-found branch from 27bf6bc to bf45582 Compare June 28, 2017 16:15
STDERR.puts

STDERR.puts ex
ex.backtrace.each do |frame|
Copy link
Contributor

@bew bew Jun 28, 2017

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bew STDOUT -> STDERR

Copy link
Contributor

@bew bew Jun 28, 2017

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 💤

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@makenowjust
Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

@RX14 RX14 Jul 10, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@RX14 RX14 Aug 29, 2017

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>

Copy link
Contributor Author

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.

Copy link
Contributor

@RX14 RX14 Aug 29, 2017

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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"
Copy link
Contributor

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

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

me too...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted for now.

@makenowjust makenowjust force-pushed the fix/crystal-format/show-backtrace-when-bug-found branch from 19b2c3d to 1563f3c Compare July 27, 2017 07:44
@makenowjust
Copy link
Contributor Author

Resolved conflicts.

@makenowjust
Copy link
Contributor Author

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) << ", "
Copy link
Contributor

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.

@makenowjust
Copy link
Contributor Author

Please merge!

@asterite
Copy link
Member

@makenowjust Could you rebase against master? CI is failing in Circle.

@makenowjust makenowjust force-pushed the fix/crystal-format/show-backtrace-when-bug-found branch from 59c72a6 to 0cacfa0 Compare October 27, 2017 14:16
@makenowjust
Copy link
Contributor Author

rebased

@asterite asterite added this to the Next milestone Oct 27, 2017
@asterite asterite merged commit ea4187c into crystal-lang:master Oct 27, 2017
@makenowjust makenowjust deleted the fix/crystal-format/show-backtrace-when-bug-found branch October 27, 2017 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants