Skip to content

Commit 07cfbec

Browse files
committed
improvement: show docs for exception function & keys in doc string
1 parent 4d93c95 commit 07cfbec

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/splode/error.ex

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,26 @@ defmodule Splode.Error do
5454
@impl Splode.Error
5555
def error_class?, do: @error_class
5656

57-
def exception, do: exception([])
57+
field_names =
58+
Enum.map(List.wrap(opts[:fields]), fn
59+
{k, _v} ->
60+
k
61+
62+
k ->
63+
k
64+
end)
5865

5966
@impl Exception
60-
def exception(opts) do
67+
@doc """
68+
Create an `#{__MODULE__}` without raising it.
69+
70+
71+
## Keys
72+
73+
#{Enum.map_join(field_names, "\n", &"- #{inspect(&1)}")}
74+
"""
75+
@spec exception(opts :: Keyword.t()) :: %__MODULE__{}
76+
def exception(opts \\ []) do
6177
if @error_class && match?([%error{class: :special} = special], opts[:errors]) do
6278
special_error = Enum.at(opts[:errors], 0)
6379

0 commit comments

Comments
 (0)