Under Linux, it fails to raise and exception and call stack will not be printed when following conditions are met:
crystal run or crystal eval is not applicable)Simple reproducible code is:
Dir.cd("/")
raise ""
[momonga@elma ~/crystal x86_64]$ cat foo.cr
Dir.cd(%[/]); raise %[]
[momonga@elma ~/crystal x86_64]$ bin/crystal build foo.cr
Using compiled compiler at `.build/crystal'
[momonga@elma ~/crystal x86_64]$ ./foo
Failed to raise an exception: END_OF_STACK
[0x446df6] *CallStack::print_backtrace:Int32 +118
[0x42d4b6] __crystal_raise +86
[0x42d9de] ???
[0x45be96] *Crystal::System::File::open<String, String, File::Permissions>:Int32 +214
[0x4598d3] *File::new<String, String, File::Permissions, Nil, Nil>:File +67
[0x43df1d] *CallStack::read_dwarf_sections:(Array(Tuple(UInt64, UInt64, String)) | Nil) +109
[0x43dcad] *CallStack::decode_line_number<UInt64>:Tuple(String, Int32, Int32) +45
[0x43d468] *CallStack#decode_backtrace:Array(String) +296
[0x43d322] *CallStack#printable_backtrace:Array(String) +50
[0x481d8d] *Exception+ +77
[0x481bf8] *Exception+ +120
[0x48037a] *AtExitHandlers::run<Int32>:Int32 +490
[0x48936b] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +139
[0x437b76] main +6
[0x7fb87b0d4c47] __libc_start_main +231
[0x42c4aa] _start +42
[0x0] ???
Also, using PATH variable to launch the executable, same problem occurs:
PATH variablemomonga@elma ~/crystal x86_64]$ bin/crystal build foo.cr
Using compiled compiler at `.build/crystal'
[momonga@elma ~/crystal x86_64]$ (PATH=$(pwd):$PATH; cd ..; foo)
Failed to raise an exception: END_OF_STACK
[0x446df6] *CallStack::print_backtrace:Int32 +118
[0x42d4b6] __crystal_raise +86
[0x42d9de] ???
[0x45be96] *Crystal::System::File::open<String, String, File::Permissions>:Int32 +214
[0x4598d3] *File::new<String, String, File::Permissions, Nil, Nil>:File +67
[0x43df1d] *CallStack::read_dwarf_sections:(Array(Tuple(UInt64, UInt64, String)) | Nil) +109
[0x43dcad] *CallStack::decode_line_number<UInt64>:Tuple(String, Int32, Int32) +45
[0x43d468] *CallStack#decode_backtrace:Array(String) +296
[0x43d322] *CallStack#printable_backtrace:Array(String) +50
[0x481d8d] *Exception+ +77
[0x481bf8] *Exception+ +120
[0x48037a] *AtExitHandlers::run<Int32>:Int32 +490
[0x48936b] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +139
[0x437b76] main +6
[0x7fbd5463bc47] __libc_start_main +231
[0x42c4aa] _start +42
[0x0] ???
Output of crystal version is:
Using compiled compiler at `.build/crystal'
Crystal 0.31.0-dev [6ec323f1d] (2019-08-13)
LLVM: 8.0.1
Default target: x86_64-unknown-linux-gnu
This can be shell-dependent: I'm using Bash 5.0.7.
Probably related to #7198
On MacOS it doesn't change dir but shows this:
$ ./test
Unhandled exception: (Exception)
from test.cr:2:1 in '__crystal_main'
from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:97:5 in 'main_user_code'
from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:86:7 in 'main'
from /usr/local/Cellar/crystal/0.31.1/src/crystal/main.cr:106:3 in 'main'
Crystal 0.31.1 on MacOS
$ crystal --version
Crystal 0.31.1 (2019-10-02)
LLVM: 8.0.1
Default target: x86_64-apple-macosx
@vlazar It is the expected result for the example. If it fails to change the directory, you should get a proper message, such as "No such file or directory", instead of an empty message.
Possibly fixed https://github.com/crystal-lang/crystal/pull/8807
Seems to be fixed on master.