open-api-spex / open_api_spex

Open API Specifications for Elixir Plug applications
Mozilla Public License 2.0
706 stars 183 forks source link

Raise meaningful error message when SchemaResolver.resolve_schema_modules_from_schema failed to pattern match #541

Closed yuchunc closed 1 year ago

yuchunc commented 1 year ago

I ran in to an unreadable error while working, and it took me a long time to realized I was doing:

%Schema{
  type: :object, 
  properties: %{
    data: %{}
  }
}

instead of:

%Schema{
  type: :object, 
  properties: %{
    data: %Schema{}
  }
}

This PR will raise with some (I think) helpful error message.

zorbash commented 1 year ago

Hi @yuchunc thanks for reporting this issue. What is the unreadable error you're currently getting? Is it a MatchError?

yuchunc commented 1 year ago

Thank you @zorbash for the quick review! It was a FunctionClauseError, and the output is 2 full console log, so it's a bit hard to understand what went wrong. We all have come across this issue at some point while working with OpenApiSpex, so thought giving a bit more context to this error. 🙏