My Crystal 程序输出到 STDOUT,通常通过管道传输到像 less
这样的寻呼机中。当用户在查看完整输出之前终止less
时,应用程序将崩溃并出现以下异常:
Unhandled exception: Error writing file: Broken pipe (Errno)
from /usr/local/Cellar/crystal/0.28.0/src/crystal/system/unix/file_descriptor.cr:79:13 in 'unbuffered_write'
from /usr/local/Cellar/crystal/0.28.0/src/io/buffered.cr:179:5 in 'flush'
from /usr/local/Cellar/crystal/0.28.0/src/io/buffered.cr:131:7 in 'write'
from /usr/local/Cellar/crystal/0.28.0/src/io.cr:481:7 in 'write_utf8'
from /usr/local/Cellar/crystal/0.28.0/src/string.cr:4254:5 in 'to_s'
from /usr/local/Cellar/crystal/0.28.0/src/io.cr:184:5 in '<<'
from /usr/local/Cellar/crystal/0.28.0/src/io.cr:227:5 in 'puts'
from /usr/local/Cellar/crystal/0.28.0/src/kernel.cr:366:3 in 'puts'
from lib/log.cr:16:9 in 'print'
from src/thicket.cr:69:3 in '__crystal_main'
from /usr/local/Cellar/crystal/0.28.0/src/crystal/main.cr:97:5 in 'main_user_code'
from /usr/local/Cellar/crystal/0.28.0/src/crystal/main.cr:86:7 in 'main'
from /usr/local/Cellar/crystal/0.28.0/src/crystal/main.cr:106:3 in 'main'
Failed to raise an exception: END_OF_STACK
[0x1056c232b] *CallStack::print_backtrace:Int32 +107
[0x105692753] __crystal_raise +83
[0x1056ec7cb] *IO::FileDescriptor@Crystal::System::FileDescriptor#unbuffered_write<Slice(UInt8)>:Nil +203
[0x1056ec691] *IO::FileDescriptor@IO::Buffered#flush:IO::FileDescriptor +81
[0x10572899e] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +142
[0x10569cfb9] main +9
我无法找到可用于解决此问题的异常类。在 Ruby 中,我会使用 Errno::EPIPE
,但 Errno::EPIPE
不是 Crystal 中 Exception
的子类。
如果我拯救Errno
,未处理的异常会消失,但其余的仍然存在:
Failed to raise an exception: END_OF_STACK
[0x10d40910b] *CallStack::print_backtrace:Int32 +107
[0x10d3d9533] __crystal_raise +83
[0x10d4335ab] *IO::FileDescriptor@Crystal::System::FileDescriptor#unbuffered_write<Slice(UInt8)>:Nil +203
[0x10d433471] *IO::FileDescriptor@IO::Buffered#flush:IO::FileDescriptor +81
[0x10d46f8fe] *Crystal::main<Int32, Pointer(Pointer(UInt8))>:Int32 +142
[0x10d3e3d99] main +9
这只是
当前版本中的错误,您正在点击 https://github.com/crystal-lang/crystal/issues/7810