wasmerio/wasmer · error · anyhow::Error

user agent must not be empty

Error message

user agent must not be empty

What it means

WasmerClient's parse_user_agent rejects an empty user-agent string with this bail before ever building the HTTP client. A reqwest HeaderValue built from an empty string would be useless/invalid for the backend API, so the constructor treats it as a configuration error and returns an anyhow error.

Source

Thrown at lib/backend-api/src/client.rs:45

impl WasmerClient {
    /// Env var used to enable logging of request variables.
    ///
    /// This is somewhat dangerous since it can log sensitive information, hence
    /// it is gated by a custom env var.
    const ENV_VAR_LOG_VARIABLES: &'static str = "WASMER_API_INSECURE_LOG_VARIABLES";

    pub fn graphql_endpoint(&self) -> &Url {
        &self.graphql_endpoint
    }

    pub fn auth_token(&self) -> Option<&str> {
        self.auth_token.as_deref()
    }

    fn parse_user_agent(user_agent: &str) -> Result<reqwest::header::HeaderValue, anyhow::Error> {
        if user_agent.is_empty() {
            bail!("user agent must not be empty");
        }
        user_agent
            .parse()
            .with_context(|| format!("invalid user agent: '{user_agent}'"))
    }

    pub fn new_with_client(
        client: reqwest::Client,
        graphql_endpoint: Url,
        user_agent: &str,
    ) -> Result<Self, anyhow::Error> {
        let log_variables = {
            let v = std::env::var(Self::ENV_VAR_LOG_VARIABLES).unwrap_or_default();
            match v.as_str() {
                "1" | "true" => true,
                "0" | "false" => false,
                // Default case if not provided.
                "" => false,

View on GitHub (pinned to 8c4b9ee9d3)

Solutions

  1. Pass a non-empty user agent string, e.g. "my-app/1.0" or concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")).
  2. Add a fallback default when the value comes from config/env: if empty, substitute a sensible default.
  3. Trim whitespace and validate before constructing the client.

Example fix

// before
let client = WasmerClient::new(endpoint, "")?;
// after
let ua = if user_agent.trim().is_empty() {
    format!("{}/{}", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"))
} else { user_agent.to_string() };
let client = WasmerClient::new(endpoint, ua)?;
Defensive patterns

Strategy: validation

Validate before calling

fn build_user_agent(ua: &str) -> anyhow::Result<String> {
    let ua = ua.trim();
    if ua.is_empty() {
        anyhow::bail!("user agent must not be empty");
    }
    Ok(ua.to_string())
}

Type guard

fn is_valid_user_agent(ua: &str) -> bool { !ua.trim().is_empty() }

Try / catch

// construction is fallible anyway
let client = WasmerClient::new(endpoint, ua)
    .map_err(|e| e.context("invalid client configuration (check user_agent)"))?;

Prevention

When it happens

Trigger: Constructing WasmerClient (new / new_with_client path) with user_agent = "" — e.g. WasmerClient::new(url, "") or reading a user agent from an unset variable without a default.

Common situations: CI scripts or CLI wrappers passing an empty UA; an env var like WASMER_USER_AGENT set to empty; forgotten default value in library configuration.

Related errors


AI-assisted analysis of wasmerio/wasmer@8c4b9ee9d3 (2026-09-01). Data as JSON: /api/errors/e5f5c9c4e5c2f446. Report an issue: GitHub.