reqwest::ClientBuilder is erroring out silently

Hi there, I am a newbie on rust, came across a problem on reqwest client


mod utils;
use reqwest::ClientBuilder;
use std::io::{self, Write};


#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("Initializing client:");

    let client = match ClientBuilder::new().build() {
        Ok(client) => {
            println!("Done building reqwest client");
            io::stdout().flush().unwrap();
            client
        },
        Err(e) => {
            eprintln!("Error creating HTTP client: {}", e);  // Print the error message
            println!("Error creating HTTP client: {:?}, Error Type: {:?}", e, e);
            io::stderr().flush().unwrap();
            // Box the `reqwest::Error` to match the expected `Box<dyn std::error::Error>` type
            return Err(Box::new(e) as Box<dyn std::error::Error>);
        }
    };

    println!("Done creating  client:");

    Ok(())
}

I noticed that the code is not printing out any messages from OK or Err. It only prints "Initializing client:." I cannot reproduce it locally on my Windows machine. Please let me know what could be wrong with this code.

After removing the strange second main function that sets a panic hook (which you since removed from your snippet as well), your code runs fine on the playground:

Initializing client:
Done building reqwest client
Done creating  client:

Thank you. Yes that was a copy/paste error.

I've updated my code to the following:

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    println!("Creating client");

    let result = panic::catch_unwind(|| {
        // Create the reqwest client
        let client = reqwest::Client::new();
        println!("Client created: {:?}", client);
    });

    match result {
        Ok(_) => println!("Client created successfully"),
        Err(e) => {
            println!("Error creating client: {:?}", e);
            return Err("Failed to create client".into());
        }
    }

    Ok(())
}

This code run fine on my windows machine. But on an alpine image, only the first statement, "Creating client" is printed. Does the reqwest::Client not work on Alpine?

I'm not sure what the cause of this is. What features have you enabled? Maybe try disabling the default features and see if you can get ClientBuilder::build to finish? You can disable the default features in your manifest like this:

[dependencies]
reqwest = { version = "0.12", default-features = false }