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

Better error for named top-level union #55

Closed
davydog187 opened this issue Feb 22, 2022 · 1 comment · Fixed by #62
Closed

Better error for named top-level union #55

davydog187 opened this issue Feb 22, 2022 · 1 comment · Fixed by #62

Comments

@davydog187
Copy link
Member

Top-level unions cannot be named (I think?). The current behavior needs to be adjusted accordingly to what the spec says.

Possibly helpful fastavro/fastavro#388

     test/encode_test.exs:393
     ** (FunctionClauseError) no function clause matching in AvroEx.Schema.cast/1

     The following arguments were given to AvroEx.Schema.cast/1:
     
         # 1
         %{"name" => "maybe_null", "type" => ["null", "string"]}
     
     Attempted function clauses (showing 10 out of 25):
     
         def cast(nil)
         def cast("null")
         def cast("boolean")
         def cast("int")
         def cast("long")
         def cast("float")
         def cast("double")
         def cast("bytes")
         def cast("string")
         def cast(%{"type" => nil} = data)
         ...
         (15 clauses not shown)
     
     code: schema = AvroEx.parse_schema!(~S({"type": ["null", "string"], "name": "maybe_null"}))
     stacktrace:
@davydog187
Copy link
Member Author

Regardless, unions are supported at the top-level via ["null", "string"] in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant