Skip to content

Handle non-200 response codes from registry nicely #3995

@Nemo157

Description

@Nemo157

Currently crates.io always returns a 200 status code unless cargo's token is invalid/nonexistent (or there is an internal error), any errors for cargo are then returned in a json object (e.g. validation of the Cargo.toml fields during a publish).

I attempted to change crates.io to return a 400 status code, but cargo does not handle these nicely

→ cargo publish --allow-dirty --host http://localhost:8888/git/index
    Updating registry `http://localhost:8888/git/index`
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See http://doc.crates.io/manifest.html#package-metadata for more info.
   Packaging blah v0.1.0 (file:///Users/Nemo157/sources/blah)
   Verifying blah v0.1.0 (file:///Users/Nemo157/sources/blah)
   Compiling blah v0.1.0 (file:///Users/Nemo157/sources/blah/target/package/blah-0.1.0)
    Finished dev [unoptimized + debuginfo] target(s) in 0.12 secs
   Uploading blah v0.1.0 (file:///Users/Nemo157/sources/blah)
error: failed to get a 200 OK response, got 400
headers:
    HTTP/1.1 400 Bad Request

    Set-Cookie: cargo_session=--M9k+4zBMnWwFxkGyd/n7KZ2H/dU=; HttpOnly; Path=/

    Content-Type: application/json; charset=utf-8

    Content-Length: 171



body:
{"errors":[{"detail":"missing or empty metadata fields: description, license. Please see http://doc.crates.io/manifest.html#package-metadata for how to upload metadata"}]}

I have opened a ticket at rust-lang/crates.io#712 as well, it's probably worth discussing whether this is a change that is wanted at all there, before discussing any kind of implementation details here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions