Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose dropshot's http and hyper dependencies #250

Closed
wants to merge 2 commits into from

Conversation

jmpesp
Copy link

@jmpesp jmpesp commented Jan 20, 2022

Users constructing dropshot::HttpError manually do not have access to
the StatusCode type, and instead of requiring them to keep their http
dependency in sync with dropshot expose dropshot's StatusCode. That way,
users can do:

HttpError {
    status_code: dropshot::StatusCode::NOT_FOUND,
    ...
}

Users constructing dropshot::HttpError manually do not have access to
the StatusCode type, and instead of requiring them to keep their http
dependency in sync with dropshot expose dropshot's StatusCode. That way,
users can do:

    HttpError {
        status_code: dropshot::StatusCode::NOT_FOUND,
        ...
    }
@ahl
Copy link
Collaborator

ahl commented Jan 20, 2022

Good idea! I like it. @davepacheco any objections?

@jmpesp
Copy link
Author

jmpesp commented Jan 20, 2022

I might even propose generalizing this to expose dropshot's http - so one can do something like

dropshot::http::Response::builder()
  .status(dropshot::http::StatusCode::UNAUTHORIZED)
  ....

@jmpesp
Copy link
Author

jmpesp commented Jan 20, 2022

Plus hyper? :)

@davepacheco
Copy link
Collaborator

Yeah, I can see how this is annoying for consumers. But would exposing http (and hyper?) cause problems for consumers that already need their own version? I guess they'd have to keep that in sync, but they already have to do that, so maybe it's no worse?

I remember running into problems with a similar idea under #70. But I think in that case the reason is had to do with the crate in question (json-schema) exposing a macro. I don't think we're using http or hyper macros here. I wonder if the same advice is worthwhile: try updating omicron to a version of dropshot with this change before we commit to it here, in case we find some unforeseen problem with how this would affect consumers?

@davepacheco
Copy link
Collaborator

(sorry for the double-comment)

I think some crates do use this pattern of publicly exposing some internal dependency. I went to check hyper, which exposes some http items). As a new user, I remember finding this very confusing. While the page is labeled hyper::StatusCode, the docs come from http, and sometimes use terms differently than the module I thought the item was in.

Are there any guidelines on this best practice? I did find this draft. I found a few other discussions. It seems like this is reasonably idiomatic?

@jmpesp
Copy link
Author

jmpesp commented Jan 20, 2022

I can't speak to how idiomatic it is, but I got the idea from tokio-rustls.

I was also searching for a way for cargo to track the dependency of a dependency, but that seems a little more heavy. This way when dropshot updates a dependency there aren't any changes to consumer code.

@jmpesp jmpesp changed the title expose StatusCode type to consumers Expose dropshot's http and hyper dependencies Jan 20, 2022
@davepacheco
Copy link
Collaborator

(sorry again -- I should probably finish whatever digging I'm going to do before commenting here :-/)

Interestingly, I'm not the only one that finds that doc behavior confusing. And this comment about whether every crate that exposes future-stuff ought to re-export futures raises a similar question to the one above. Suppose we have multiple crates in omicron that use http::StatusCode. If omicron wants to share a http::StatusCode between them, could it wind up in the bizarre position of having to convert foo::http::StatusCode::NOT_FOUND to dropshot::http::StatusCode::NOT_FOUND? Or maybe we avoid that by saying dropshot and foo should have relaxed semver constraints on http such that Cargo will wind up picking the same one? Is that better than the status quo?

@jmpesp
Copy link
Author

jmpesp commented Jan 20, 2022

If omicron wants to share a http::StatusCode between them, could it wind up in the bizarre position of having to convert foo::http::StatusCode::NOT_FOUND to dropshot::http::StatusCode::NOT_FOUND?

This sentence made me think that it would be better if Cargo could follow a dependency of a dependency. Some fake syntax in omicron like:

http = { transitive = ["dropshot", "foo"] }

which interestingly could enforce that foo and dropshot have matching http versions (does Cargo already complain if the http versions can't be made to match?). But this would complicate the dep graph quite a bit I think.

@ahl
Copy link
Collaborator

ahl commented Jan 21, 2022

@davepacheco FWIW I believe the issue with #70 as it pertained to JsonSchema (and serde derive macros) was unique to derive macros in that their generated code embeds particular crate names.

@jmpesp
Copy link
Author

jmpesp commented Feb 10, 2022

Closing this

@jmpesp jmpesp closed this Feb 10, 2022
@jmpesp jmpesp deleted the expose_status_code_type branch February 10, 2022 21:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants