Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Humanize errors #5

Open
visciang opened this issue Jun 4, 2022 · 0 comments
Open

Humanize errors #5

visciang opened this issue Jun 4, 2022 · 0 comments
Labels
enhancement New feature or request

Comments

@visciang
Copy link
Owner

visciang commented Jun 4, 2022

Improve the error "stack" trace.

defmodule Test.DataSpecs.A do
  @moduledoc false

  use DataSpecs

  @enforce_keys [:f_1]
  defstruct [:f_1]

  @type t :: %__MODULE__{
          f_1: %{a: [atom() | {integer(), term()}]},
        }
end

The following incorrect value:

%Test.DataSpecs.A{f_1: %{a: [:a, {:"BAD TYPE HERE", 1}]}}
|> Test.DataSpecs.A.load()

produce this error:

{:error,
 [
   "can't convert %Test.DataSpecs.A{f_1: %{a: [:a, {:\"BAD TYPE HERE\", 1}]}} to a %Test.DataSpecs.A{} struct",
   ["can't convert %Test.DataSpecs.A{f_1: %{a: [:a, {:\"BAD TYPE HERE\", 1}]}} to a map, bad k/v pairs: %{f_1: %{a: [:a, {:\"BAD TYPE HERE\", 1}]}}",
    []]
 ]}

While correct a bit cryptic. Should be humanized!

Ideally should report something like:

%Test.DataSpecs.A{f_1: %{a: [:a, {:"BAD TYPE HERE", 1}]}}
                                  ^
Expected an integer(), got an atom()
@visciang visciang added the enhancement New feature or request label Jun 4, 2022
@visciang visciang moved this to 📋 Backlog in dataspec next major Sep 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant