Skip to content

Commit

Permalink
Enable full backtrace for exception in process spawn (#14796)
Browse files Browse the repository at this point in the history
If an exception raises in the code that prepares a forked process for `exec`, the error message of this exception is written through a pipe to the original process, which then raises an exception for the calling code (`Process.run`).
The error only includes a message, no stack trace. So the only stack trace you get is that of the handler which reads the message from the pipe and raises in the original process. 
But that's not very relevant. We want to know the location of the original exception.
This patch changes from sending just the exception message, to printing the entire backtrace (`inspect_with_backtrace`).
  • Loading branch information
straight-shoota committed Aug 7, 2024
1 parent d738ac9 commit edce0a3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/crystal/system/unix/process.cr
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 243,9 @@ struct Crystal::System::Process
writer_pipe.write_bytes(Errno.value.to_i)
rescue ex
writer_pipe.write_byte(0)
writer_pipe.write_bytes(ex.message.try(&.bytesize) || 0)
writer_pipe << ex.message
message = ex.inspect_with_backtrace
writer_pipe.write_bytes(message.bytesize)
writer_pipe << message
writer_pipe.close
ensure
LibC._exit 127
Expand Down

0 comments on commit edce0a3

Please sign in to comment.