ash-project / ash_json_api

The JSON:API extension for the Ash Framework
https://hexdocs.pm/ash_json_api
MIT License
56 stars 40 forks source link

Errors on required attributes are missing a way to relate them to the source attribute #116

Closed rbino closed 5 months ago

rbino commented 5 months ago

Describe the bug I'm upgrading to Ash 3.0 and the errors do not include a reference to the attribute triggering them anymore, neither in details nor in source. I've encountered this specific behavior on Required errors so I'm not sure it's generalized or not.

Ash 2.0 error

%{
  "errors" => [
    %{
      "code" => "required",
      "detail" => "attribute name is required",
      "id" => "10ec9a41-e8d0-4cf6-ba86-05279b7b4b0f",
      "source" => %{"pointer" => "/data/attributes/name"},
      "status" => "400",
      "title" => "required"
    },
    %{
      "code" => "required",
      "detail" => "attribute slug is required",
      "id" => "a7d4fd87-28ce-4823-94b4-a1507db18537",
      "source" => %{"pointer" => "/data/attributes/slug"},
      "status" => "400",
      "title" => "required"
    }
  ],
  "jsonapi" => %{"version" => "1.0"}
}

Ash 3.0 error

%{
  "errors" => [
    %{
      "code" => "required",
      "detail" => "is required",
      "id" => "6b6f68de-52b8-4032-8a42-039d8ccc54c9",
      "meta" => %{},
      "status" => "400",
      "title" => "Required"
    },
    %{
      "code" => "required",
      "detail" => "is required",
      "id" => "512ea8a7-5c32-4f9b-a315-26434cecf387",
      "meta" => %{},
      "status" => "400",
      "title" => "Required"
    },
  ],
  "jsonapi" => %{"version" => "1.0"}
}

Expected behavior There should be a way to know what attribute triggered an error

zachdaniel commented 5 months ago

🤔 yeah, looks like we removed the source pointer logic in the errors refactor and didn't add it back in.

zachdaniel commented 5 months ago

Can you try out main? Behavior should be restored.

rbino commented 5 months ago

It works, there's still another issue that was there also before Ash 3.0 so I'll open a separate issue for that