Skip to content

Better error message when path argument does not start with a forward slash #26

Description

@CameronBieganek

Example:

julia> HTTP.URI(; scheme="https", host="julialang.org", path="foo/bar")
ERROR: ArgumentError: merge(::HTTP.URIs.URI; scheme::String, userinfo::SubString{String}, host::String, port::SubString{String}, path::String, query::SubString{String}, fragment::SubString{String}) requires !(scheme in ["http", "https"]) || (isempty(path) || path[1] == '/')
Stacktrace:
 [1] macro expansion at /Users/bieganek/.julia/packages/HTTP/GkPBm/src/debug.jl:52 [inlined]
 [2] merge(::HTTP.URIs.URI; scheme::String, userinfo::SubString{String}, host::String, port::SubString{String}, path::String, query::SubString{String}, fragment::SubString{String}) at /Users/bieganek/.julia/packages/HTTP/GkPBm/src/URIs.jl:81
 [3] #URI#3 at /Users/bieganek/.julia/packages/HTTP/GkPBm/src/URIs.jl:66 [inlined]
 [4] top-level scope at REPL[31]:1

That's not a terribly helpful error message. If you look really closely you can see the (isempty(path) || path[1] == '/') part at the end, but it's easy to miss.

In addition to a better error message, it would be a good idea to explicitly mention in the docstring that path must start with a forward slash.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions