【发布时间】:2017-12-11 21:57:52
【问题描述】:
在 elixir 中,您可以像这样定义自定义异常:
defmodule AppWeb.CustomError do
defexception message: "some custom server error", plug_status: 500
end
但这不再是Elixir.Exception
因此,如果您将它与定义了这种类型规范的第三方库一起使用:
@spec capture_exception(Exception.t, Keyword.t) :: task
def capture_exception(exception, opts \\ []) do
...
Sentry.capture_exception(AppWeb.CustomError,
[stacktrace: System.stacktrace()]
dialyzer 将与 breaks the contract 一起崩溃,因为 CustomError 不是异常:
电话 'Elixir.Sentry':capture_exception('Elixir.AppWeb.CustomError',[{'stacktrace',[{atom(),atom(),[any()] |字节(),[{'文件',字符串()} | {'line',pos_integer()}]}]},...]) 中断 合约 ('Elixir.Exception':t(),'Elixir.Keyword':t()) -> task()
你能以某种方式在AppWeb.CustomError 中扩展Elixir.Exception 模块吗?或者如何遵循最佳实践来处理?
【问题讨论】:
-
Sentry.capture_exception(%AppWeb.CustomError{}, ...)工作吗?
标签: elixir phoenix-framework dialyzer