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

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

Conversation

yuchunc
Copy link
Contributor

@yuchunc yuchunc commented May 26, 2023

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
Copy link
Contributor

zorbash commented May 26, 2023

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

@@ -250,6 +250,19 @@ defmodule OpenApiSpex.SchemaResolver do

defp resolve_schema_modules_from_schema(ref = %Reference{}, schemas), do: {ref, schemas}

defp resolve_schema_modules_from_schema(_, _) do
error_message = """
Cannot resolve schema, need to be one of:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] needs to be

@yuchunc
Copy link
Contributor Author

yuchunc commented May 27, 2023

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. 🙏

@zorbash zorbash merged commit 2ca69e0 into open-api-spex:master May 29, 2023
zorbash added a commit that referenced this pull request May 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants