在 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()] | byte(),[{'file', string()} | {'line',pos_integer()}]}]},...]) 违反合约('Elixir.Exception':t(),'Elixir.Keyword':t()) ->任务()
你能以某种方式扩展Elixir.Exception
模块AppWeb.CustomError
吗?或者如何遵循最佳实践来解决这个问题?