Skip to content

fix: add panic error when multiple HTTP features are enabled #3003

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gruebel
Copy link
Member

@gruebel gruebel commented May 23, 2025

Fixes #2994

Changes

  • I didn't add it to the changelog, because it fails already, but with a not very helpful error message 😅

Merge requirement checklist

  • CONTRIBUTING guidelines followed
  • Unit tests added/updated (if applicable)
  • Appropriate CHANGELOG.md files updated for non-trivial, user-facing changes
  • Changes in public API reviewed (if applicable)

@gruebel gruebel requested a review from a team as a code owner May 23, 2025 19:14
Copy link

codecov bot commented May 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.2%. Comparing base (8882c31) to head (5ba7a84).

Additional details and impacted files
@@           Coverage Diff           @@
##            main   #3003     +/-   ##
=======================================
+ Coverage   81.0%   81.2%   +0.1%     
=======================================
  Files        126     126             
  Lines      24753   24727     -26     
=======================================
+ Hits       20070   20091     +21     
+ Misses      4683    4636     -47     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cijothomas cijothomas requested a review from Copilot May 23, 2025 19:23
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR ensures that enabling more than one HTTP client feature results in a clear panic and adds a test for that case.

  • Adds a runtime panic! when multiple client features are active to prevent ambiguous configurations
  • Introduces a unit test that verifies the panic is triggered under conflicting feature sets

Co-authored-by: Björn Antonsson <ban@rhsh.net>
Comment on lines +164 to +171
#[cfg(any(
all(feature = "hyper-client", feature = "reqwest-client"),
all(feature = "hyper-client", feature = "reqwest-blocking-client"),
all(feature = "reqwest-client", feature = "reqwest-blocking-client")
))]
{
return Err(ExporterBuildError::InternalFailure("Can't enable more than one HTTP client features simultaneously. Please choose only one: hyper-client, reqwest-client, or reqwest-blocking-client (default feature)".to_string()));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is a good idea.
Because of feature unification, if you depend transitively on a crate, it might enable features which you do not explicitely have

A consequence of this is that features should be additive. That is, enabling a feature should not disable functionality, and it should usually be safe to enable any combination of features. A feature should not introduce a SemVer-incompatible change

https://doc.rust-lang.org/cargo/reference/features.html#feature-unification

I think a cleaner idea would be to define an order of precedence between clients (for instance reqwest-client > hyper-client > reqwest-blocking-client) and use the client with the higher precendence if multiple features are enabled

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.

[Bug]: NoHttpClient error when reqwest-client feature is enabled
4 participants