Skip to content

Handle non-200 response codes from registry nicely #3995

@Nemo157

Description

@Nemo157
Member

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.

Activity

alexcrichton

alexcrichton commented on May 5, 2017

@alexcrichton
Member

Yeah definitely! Cargo's handling of responses from the registry is... not the best unfortunately. We should at the very least try to extract the errors coming back and package that up in a nice fashion to send to the user.

If you'd be interested in implementing this I'd be more than willing to mentor!

ehuss

ehuss commented on May 20, 2019

@ehuss
Contributor

This has been updated in #6771 to always show the JSON errors in a nicer way, regardless of the error code. I'm going to close this for now, as I think the spirit of the issue has been addressed. If there are ways to further clarify the error messages, feel free to open a new issue.

added a commit that references this issue on Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ehuss@alexcrichton@Nemo157@carols10cents

        Issue actions

          Handle non-200 response codes from registry nicely · Issue #3995 · rust-lang/cargo