Skip to content

Commit

Permalink
Enhance error message readability
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKlo committed Dec 16, 2024
1 parent 797552c commit 5a56440
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/De/De.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,17 @@ struct WrongType <: DeserError
end

function Base.show(io::IO, e::WrongType)
return print(
io,
"WrongType: for '$(e.maintype)' value '$(e.value)' has wrong type '$(e.key)::$(e.from_type)', must be '$(e.key)::$(e.to_type)'",
)
return if e.value == "Ptr{YYJSONVal}"
print(
io,
"WrongType: for '$(e.maintype)' got wrong type '$(e.key)::$(e.from_type)', must be '$(e.key)::$(e.to_type)'",
)
else
print(
io,
"WrongType: for '$(e.maintype)' value '$(e.value)' has wrong type '$(e.key)::$(e.from_type)', must be '$(e.key)::$(e.to_type)'",
)
end
end

include("Deser.jl")
Expand Down
2 changes: 1 addition & 1 deletion test/deser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ using Test, Dates
end

exp_str = """ {"correlation_id":2,"method":"subscribe.status","payload":{}} """
@test_throws "WrongType: for 'Message{Nothing}' value 'Ptr{YYJSONVal}' has wrong type 'payload::Dict{String, Any}', must be 'payload::Nothing'" Serde.deser_json(
@test_throws "WrongType: for 'Message{Nothing}' got wrong type 'payload::Dict{String, Any}', must be 'payload::Nothing'" Serde.deser_json(
Message{Nothing},
exp_str,
)
Expand Down

0 comments on commit 5a56440

Please sign in to comment.