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

Unify way of printing exceptions from within fibers #6594

Merged
merged 1 commit into from
Sep 10, 2018

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Aug 23, 2018

There was slight inconsistency how these exceptions were printed to STDERR (puts vs print), now they should be even. I've also added STDERR.flush missing from AtExitHandlers.run.

For the reference:

crystal/src/kernel.cr

Lines 404 to 405 in 5e059ab

STDERR.print "Unhandled exception: "
ex.inspect_with_backtrace(STDERR)

vs

crystal/src/fiber.cr

Lines 122 to 128 in 5e059ab

if name = @name
STDERR.puts "Unhandled exception in spawn(name: #{name}):"
else
STDERR.puts "Unhandled exception in spawn:"
end
ex.inspect_with_backtrace STDERR
STDERR.flush

@Sija Sija force-pushed the unify-spawn-exception-printing branch from 73ceedc to cc9e39d Compare August 23, 2018 20:41
@Sija
Copy link
Contributor Author

Sija commented Aug 23, 2018

Weird, CI flunked (but just once) with the error below:

./bin/crystal build  -o .build/std_spec spec/std_spec.cr
.build/std_spec 

...............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*.................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Nil assertion failed (Exception)
  from src/class.cr:148:0 in 'not_nil!'
  from spec/std/signal_spec.cr:0:23 in '->'
  from src/signal.cr:255:3 in '->'
  from src/signal.cr:255:3 in 'process'
  from src/signal.cr:174:9 in '->'
  from src/fiber.cr:255:3 in 'run'
  from src/fiber.cr:29:34 in '->'
  from ???

FATAL: uncaught exception while processing handler for CHLD, exiting

Makefile:89: recipe for target 'std_spec' failed
make: *** [std_spec] Error 1

@straight-shoota
Copy link
Member

This CI error happens infrequently. Don't know why. It's not related to this PR at least.

Copy link
Member

@straight-shoota straight-shoota left a comment

Choose a reason for hiding this comment

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

Maybe puts everywhere would be better?

@Sija
Copy link
Contributor Author

Sija commented Aug 23, 2018

@straight-shoota Out of these two I prefer print, since puts will add a newline before the Exception message which ain't look good (to my eyes at least).

@Sija
Copy link
Contributor Author

Sija commented Aug 23, 2018

This CI error happens infrequently. Don't know why. It's not related to this PR at least.

I believe it's related to one of these:

typeof(Signal::PIPE.reset)
typeof(Signal::PIPE.ignore)
typeof(Signal::PIPE.trap { 1 })

@straight-shoota
Copy link
Member

Without a line break, this can become a pretty long line (consider a long fiber name and error message) and more difficult to read.

I'd prefer to add a line break after the "Unhandled exception" part.

@Sija
Copy link
Contributor Author

Sija commented Aug 23, 2018

I disagree, lines are longer by the size of "Unhandled exception: " string (which IMO is not much) and long names are seldom assigned to fibers, if at all (there are none in most of the cases).

Unhandled exception: Index out of bounds (IndexError)
  from /usr/local/Cellar/crystal/0.26.0/src/indexable.cr:596:8 in 'at'
  from /eval:1:1 in '__crystal_main'
  from /usr/local/Cellar/crystal/0.26.0/src/crystal/main.cr:104:5 in 'main_user_code'
  from /usr/local/Cellar/crystal/0.26.0/src/crystal/main.cr:93:7 in 'main'
  from /usr/local/Cellar/crystal/0.26.0/src/crystal/main.cr:133:3 in 'main'

vs

Unhandled exception:
Index out of bounds (IndexError)
  from /usr/local/Cellar/crystal/0.26.0/src/indexable.cr:596:8 in 'at'
  from /eval:1:1 in '__crystal_main'
  from /usr/local/Cellar/crystal/0.26.0/src/crystal/main.cr:104:5 in 'main_user_code'
  from /usr/local/Cellar/crystal/0.26.0/src/crystal/main.cr:93:7 in 'main'
  from /usr/local/Cellar/crystal/0.26.0/src/crystal/main.cr:133:3 in 'main'

Option no. 1 is more readable to me. Also, I'd prefer not to change already established format, just because of how an edge-case might affect it (spawn with loooong name).

@Sija
Copy link
Contributor Author

Sija commented Aug 25, 2018

Could this be reviewed and possibly included in the upcoming 0.26.1 release? It's a small change so it shoudn't take much time to get through it. @RX14 @bcardiff @ysbaddaden @asterite ?

@Sija
Copy link
Contributor Author

Sija commented Sep 7, 2018

Anyone care for 2nd review? 🏓 @asterite @sdogruyol

@RX14 RX14 merged commit 58a8e27 into crystal-lang:master Sep 10, 2018
@RX14 RX14 added this to the 0.27.0 milestone Sep 10, 2018
ezrast pushed a commit to ezrast/crystal that referenced this pull request Oct 2, 2018
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.

4 participants