Skip to content

Commit

Permalink
Improved serialization failure messages (#1033)
Browse files Browse the repository at this point in the history
* improved error messages on serialization failure

* tweak wording

* changelog entry
  • Loading branch information
benwilson512 authored Jan 20, 2021
1 parent f928288 commit fd567c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.6.1

- Feature: [Improved serialization failure messages](https://github.com/absinthe-graphql/absinthe/pull/1033)

## 1.6.0

- Feature: [Interfaces can now implement Interfaces](https://github.com/absinthe-graphql/absinthe/pull/1012), matching the latest spec
Expand Down
14 changes: 13 additions & 1 deletion lib/absinthe/phase/document/result.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,19 @@ defmodule Absinthe.Phase.Document.Result do
value =
case Type.unwrap(emitter.schema_node.type) do
%Type.Scalar{} = schema_node ->
Type.Scalar.serialize(schema_node, value)
try do
Type.Scalar.serialize(schema_node, value)
rescue
Absinthe.SerializationError ->
raise(Absinthe.SerializationError, """
Could not serialize term #{inspect(value)} as type #{schema_node.name}
When serializing the field:
#{emitter.parent_type.name}.#{emitter.schema_node.name} (#{
emitter.schema_node.__reference__.location.file
}:#{emitter.schema_node.__reference__.location.line})
""")
end

%Type.Enum{} = schema_node ->
Type.Enum.serialize(schema_node, value)
Expand Down

0 comments on commit fd567c7

Please sign in to comment.