crystal play when 8080 is already in use reports 'Error: you've found a bug in the Crystal compiler.'

Created on 15 Oct 2019  路  9Comments  路  Source: crystal-lang/crystal

When running from the command line

crystal play

if the port 8080 is already in use Crystal prints the following output:

bind: Address in use (Errno)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

Steps to reproduce

  1. Use the port 8080 on localhost with another process
  2. Run crystal play from the command line

Additional informations

  • Crystal version:
Crystal 0.31.1 [0e2e1d067] (2019-09-30)

LLVM: 8.0.0
Default target: x86_64-unknown-linux-gnu
  • OS: Fedora 30 Workstation
  • kernel: 5.2.18-200.fc30.x86_64
bug topicplayground

Most helpful comment

What do you think the expected action should be? I think the error message makes it pretty clear and per the docs (crystal play --help) you can specify a different port when starting. The only thing I think could be argued is that the "you have found a bug" message could be removed.

All 9 comments

What do you think the expected action should be? I think the error message makes it pretty clear and per the docs (crystal play --help) you can specify a different port when starting. The only thing I think could be argued is that the "you have found a bug" message could be removed.

Exactly. It's not a compiler bug and we don't need a stack trace.

It's actually a bit recursive:

  • it's a bug
  • the bug is that it says it's a bug

I'd like to take this on, but I have a few discussion points:

Currently, the playground is its own class that is fed arguments from a wrapper that parses the command line (good). However, the only way for the playground to exit is from that wrapper if an exception is thrown from the Playground class or the user interrupts the playground (Ctl+C). I think the most elegant solution would be to exit 1 from the Playground class if the port is already in use, but that would mean that a class is exiting the application and not the wrapper. Is this OK?

If not, I will have to create a new type of exception and then catch that exception in the wrapper class to cleanly exit without giving a stack trace. This is OK, just a little bit more work I think.

I think you just need:

begin
  playground.run
rescue Errno
  # Show some error
  exit 1
end

Yeah, that was the direction I think I was heading next, just need to make sure to put the right output depending on the error. I believe that port or address in use isn't "exceptional" and should print an error message (no stacktrace) but other exceptions should print full stacktrace because they are truly "exceptional." I'll take this one and make a PR.

What other exceptions? I think other exceptions are already caught, and they will show the "Bug found" message shown in this GitHub issue.

@rvictory rescue Errno only rescues Errno and all Errno exceptions raised by playground.run are (most likely) not compiler errors.

@straight-shoota I don't think playground.run should raise any exceptions. Any exception raised there means a bug.

Unfortunately Errno isn't very useful to detecting specific errors... well, in this case I think it's EINVALIDADRESS or something like that, but it's still ugly. If we want to fix this without changing the entire exception hierarchy, rescue Errno plus checking the errno value might be the only option for now.

Was this page helpful?
0 / 5 - 0 ratings