diff --git a/src/ProtocolDataUnits.jl b/src/ProtocolDataUnits.jl index 5ec6958..de90aaf 100644 --- a/src/ProtocolDataUnits.jl +++ b/src/ProtocolDataUnits.jl @@ -223,14 +223,14 @@ function Base.write(io::IO, pdu::T; hooks=true) where {T<:AbstractPDU} if n === WireEncoded() varwrite(io, v) elseif n === nothing - throw(ErrorException("Length of field $(f) is unknown")) + throw(ArgumentError("Length of field $(f) is unknown")) else if n === missing write(io, v) else - length(v) > n && throw(ErrorException("Value too long for field $(f) (expected $n, actual $(length(n)))")) + length(v) > n && throw(ArgumentError("Value too long for field $(f) (expected $n, actual $(length(n)))")) if length(v) < n - autopad || throw(ErrorException("Value too short for field $(f) (expected $n, actual $(length(n)))")) + autopad || throw(ArgumentError("Value too short for field $(f) (expected $n, actual $(length(n)))")) v = vcat(v, zeros(eltype(v), n - length(v))) end write(io, v) diff --git a/test/runtests.jl b/test/runtests.jl index 213a82d..273be0c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -346,7 +346,7 @@ end pdu = MyLessSimplePDU(1, "hello world! how are you?") - @test_throws ErrorException PDU.encode(pdu) + @test_throws ArgumentError PDU.encode(pdu) Base.length(::Type{MyLessSimplePDU}, ::Val{:b}, info) = info.length - 2