Skip to content

Commit

Permalink
Use consistent error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Drvi committed Dec 13, 2023
1 parent 6f3d9b1 commit 6b52c0b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/get.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ end
# until we get the response, which would return as a HTTP.RequestError from within HTTP.jl.
# The idea here is to unwrap the HTTP.RequestError and check if it's an ArgumentError, and if so,
# throw that instead, so we same exception type is thrown in this case.
# TODO(PR): Do we want to do this? If yes, do we want to make the messages the same?
function _check_buffer_too_small_exception(@nospecialize(e::Exception))
if e isa HTTP.RequestError
request_error = e.error
Expand Down Expand Up @@ -196,7 +195,8 @@ function getObjectImpl(x::AbstractStore, key::String, out::ResponseBodyType=noth
res = body = Vector{UInt8}(undef, contentLength)
elseif out isa AbstractVector{UInt8}
# user-provided buffer is allowed to be larger than actual object size, but not smaller
length(out) < contentLength && throw(ArgumentError("out ($(length(out))) must at least be of length $contentLength"))
# NOTE: wording of the error message matches what HTTP.jl throws when the buffer is too small
length(out) < contentLength && throw(ArgumentError("Unable to grow response stream IOBuffer $(length(out)) large enough for response body size: $(contentLength)"))
res = out
body = view(out, 1:contentLength)
elseif out isa String
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ check(x, y) = begin; reset!(x); reset!(y); z = read(x) == read(y); reset!(x); re
@test false # Should have thrown an error
catch e
@test e isa ArgumentError
@test e.msg == "out ($(sizeof(out))) must at least be of length $(sizeof(csv))"
@test e.msg == "Unable to grow response stream IOBuffer $(sizeof(out)) large enough for response body size: $(sizeof(csv))"
end
end

Expand Down Expand Up @@ -376,7 +376,7 @@ end
@test false # Should have thrown an error
catch e
@test e isa ArgumentError
@test e.msg == "out ($(sizeof(out))) must at least be of length $(sizeof(csv))"
@test e.msg == "Unable to grow response stream IOBuffer $(sizeof(out)) large enough for response body size: $(sizeof(csv))"
end
end

Expand Down

0 comments on commit 6b52c0b

Please sign in to comment.