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

RaiseError: keep consistent with interfaces #17

Merged
merged 1 commit into from
Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/Error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ Raise specific `error` or `ErrorException(message)` when serializing or deserial
"""
RaiseError(msg::AbstractString) = RaiseError(ErrorException(msg))

# this method is not consistent with the Construct interface,
# but it's acceptable because it never writes anything to the stream.
serialize(cons::RaiseError, ::IO, ::Any; contextkw...) = throw(cons.err)
serialize(cons::RaiseError, ::IO, ::UndefProperty; contextkw...) = throw(cons.err)
# serialize(cons::RaiseError, ::IO, ::Union{}; contextkw...) = throw(cons.err) # unreachable
deserialize(cons::RaiseError, ::IO; contextkw...) = throw(cons.err)
default(cons::RaiseError; contextkw...) = throw(cons.err)
estimatesize(cons::RaiseError; contextkw...) = ExactSize(0)
7 changes: 3 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,9 @@ end
@test estimatesize(RaiseError("Invalid data.")) == 0
@test_throws ErrorException deserialize(RaiseError("Invalid data."), b"")
@test_throws ValidationError deserialize(RaiseError(ValidationError("Invalid data.")), b"")
@test_throws ErrorException serialize(RaiseError("Invalid data."), IOBuffer(), nothing)
@test_throws ValidationError serialize(RaiseError(ValidationError("Invalid data.")), IOBuffer(), nothing)
@test_throws ErrorException serialize(RaiseError("Invalid data."), IOBuffer(), UndefProperty{Union{}}())
@test_throws ValidationError serialize(RaiseError(ValidationError("Invalid data.")), IOBuffer(), UndefProperty{Union{}}())
@test_throws ErrorException serialize(RaiseError("Invalid data."), UndefProperty{Union{}}())
@test_throws ValidationError serialize(RaiseError(ValidationError("Invalid data.")), UndefProperty{Union{}}())
@test_throws MethodError serialize(RaiseError("Invalid data."), nothing)
end
@testset "JuliaSerializer" begin
@test estimatesize(JuliaSerializer()) == UnboundedSize(0)
Expand Down