Skip to content

Commit

Permalink
log expected valid constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Nov 30, 2024
1 parent cce8c2f commit c6a71d9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "json_blueprint"
version = "1.2.0"
version = "1.2.1"

description = "Simplify JSON encoding/decoding while automatically generating JSON schemas for your data types."
licences = ["MIT"]
Expand Down
19 changes: 12 additions & 7 deletions src/json/blueprint.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,18 @@ pub fn union_type_decoder(
_ -> Error([])
}
})
|> result.replace_error([
dynamic.DecodeError(
expected: "valid constructor type",
found: type_str,
path: [],
),
])
|> result.map_error(fn(_) {
let valid_types =
decoders |> list.map(fn(dec) { dec.0 }) |> string.join(", ")

[
dynamic.DecodeError(
expected: "valid constructor type, one of: " <> valid_types,
found: type_str,
path: [],
),
]
})
}

let enum_decoder = fn(data) {
Expand Down

0 comments on commit c6a71d9

Please sign in to comment.