Skip to content

Report proxy URL on tunnel failures - #3144

Merged
seanmonstar merged 1 commit into
seanmonstar:masterfrom
konsti-openai:konsti/report-proxy-connection-errors
Nov 23, 2026
Merged

seanmonstar merged 1 commit into
seanmonstar:masterfrom
konsti-openai:konsti/report-proxy-connection-errors

Conversation

@konsti-openai

@konsti-openai konsti-openai commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

When reqwest failed to resolve the proxy instead of the destination, the error change is currently not clear and does not show the proxy URL. This PR adds a wrapper type that (after redaction) shows the proxy URL.

This adds redundancy in the error chain, but the fix requires a separate hyper-util change.

Fixes #2252

Example

use std::error::Error;
use std::process::ExitCode;
use std::time::Duration;

fn fetch() -> Result<(), reqwest::Error> {
    let client = reqwest::blocking::Client::builder()
        .proxy(reqwest::Proxy::https("http://proxy.invalid:8080")?)
        .timeout(Duration::from_secs(10))
        .build()?;
    client.get("https://example.org/").send()?;
    Ok(())
}

fn main() -> ExitCode {
    if let Err(err) = fetch() {
        eprintln!("error: {err}");
        let mut cause = err.source();
        while let Some(err) = cause {
            eprintln!("  cause: {err}");
            cause = err.source();
        }
        return ExitCode::FAILURE;
    }
    ExitCode::SUCCESS
}
 error: error sending request for url (https://example.org/)
   cause: client error (Connect)
   cause: tunnel error: failed to create underlying connection
+  cause: failed to connect to proxy (http://proxy.invalid:8080/)
   cause: dns error
   cause: error resolving DNS
   cause: failed to lookup address information: nodename nor servname provided, or not known

Comment thread src/connect.rs

/// Redact credentials before adding the proxy address to the connection error.
/// For example, report `http://user:secret@proxy:8080` as `http://proxy:8080`.
/// If the redacted address doesn't parse as a URL, omit the address entirely.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't understand URLs good enough to know if that is the right default.

@seanmonstar seanmonstar left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Looks awesome to me, thanks!

@seanmonstar
seanmonstar merged commit d81cec8 into seanmonstar:master Nov 23, 2026
63 of 117 checks passed
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.

[Feature Request] Better error messages when tunneling

2 participants