Haskell 如何在服务处理程序中打印未捕获异常的堆栈跟踪?
当我使用分析信息构建应用程序时,未捕获的异常会导致一个漂亮的堆栈跟踪打印到控制台。例如:Haskell 如何在服务处理程序中打印未捕获异常的堆栈跟踪?,haskell,exception,stack-trace,servant,Haskell,Exception,Stack Trace,Servant,当我使用分析信息构建应用程序时,未捕获的异常会导致一个漂亮的堆栈跟踪打印到控制台。例如: CallStack (from -prof): Redacted.Booking.API.Callback.Parse.parseFromEnv (src/Redacted/Booking/API/Callback/Parse.hs:(38,1)-(40,93)) Main.main.readCallbackUrl (app/Main.hs:(51,5)-(54,77)) Control.Exc
CallStack (from -prof):
Redacted.Booking.API.Callback.Parse.parseFromEnv (src/Redacted/Booking/API/Callback/Parse.hs:(38,1)-(40,93))
Main.main.readCallbackUrl (app/Main.hs:(51,5)-(54,77))
Control.Exception.Lifted.finally.\ (Control/Exception/Lifted.hs:(426,22)-(427,47))
Control.Monad.Trans.Control.liftBaseWith (Control/Monad/Trans/Control.hs:627:66-86)
Control.Monad.Trans.Control.control (Control/Monad/Trans/Control.hs:751:1-39)
Control.Exception.Lifted.finally (Control/Exception/Lifted.hs:(425,1)-(427,47))
Control.Logging.withStderrLogging (Control/Logging.hs:(165,1)-(169,24))
Redacted.Logging.withStderrLogging (src/Redacted/Logging.hs:(26,1)-(31,40))
Main.main (app/Main.hs:(37,1)-(54,77))
但是,如果在服务处理程序中发生未捕获的异常,则不会打印堆栈跟踪——只打印异常,例如:
Prelude.maximum: empty list
通过在我的Stack.yaml中包含以下内容,我正在使用Stack进行构建,同时启用库和可执行文件评测:
build:
library-profiling: true
executable-profiling: true
如何为服务处理程序内部发生的未捕获异常打印堆栈跟踪?我认为外部库必须在启用分析的情况下构建。如果您展示了如何构建应用程序/库,可能会有所帮助。@chris stryczynski我已经用我如何构建的信息更新了这篇文章。另外,我认为问题在于服务程序捕捉到异常并重新调用它——它必须这样做,才能用500状态代码响应客户机。