tw93/Pake · error

web URLs must have a host

Error message

web URLs must have a host

What it means

This is a Rust `.expect(...)` panic on `target_url.host_str()` in the macOS auth delegate setup in `build_window` (src-tauri/src/app/window.rs:743). The `url` crate returns `None` for `host_str()` when a URL has no host component (e.g. `about:blank`, `data:` URIs, or relative references), and the assertion assumes every auth target is a real web URL with a host. If an auth-target URL without a host reaches this line, the process panics instead of degrading gracefully.

Source

Thrown at src-tauri/src/app/window.rs:743

                    eprintln!("[Pake] Failed to retain the macOS window for tabbing.");
                    return;
                };
                ns_window.setTabbingMode(objc2_app_kit::NSWindowTabbingMode::Preferred);
            },
            Err(error) => {
                eprintln!("[Pake] Failed to access the macOS window for tabbing: {error}");
            }
        });
    }

    // WKWebView does not show an HTTP Basic login dialog and ignores Chromium's
    // certificate-error flag. Install one host-scoped delegate for both flows
    // on the process-lifetime main window, then navigate to the real target.
    #[cfg(target_os = "macos")]
    if let Some(target_url) = auth_target {
        let allowed_host = target_url
            .host_str()
            .expect("web URLs must have a host")
            .to_owned();
        let prompt_for_basic_auth = config.basic_auth;
        let allow_invalid_certificates = window_config.ignore_certificate_errors;
        let auth_window = window.clone();
        Queue::main().exec_async(move || {
            if let Err(error) = auth_window.with_webview(move |webview| {
                if !crate::app::auth::install_auth_delegate_and_navigate(
                    webview.inner(),
                    allowed_host,
                    target_url.to_string(),
                    prompt_for_basic_auth,
                    allow_invalid_certificates,
                ) {
                    eprintln!("[Pake] Failed to configure macOS authentication handling.");
                }
            }) {
                eprintln!("[Pake] Failed to access the macOS webview: {error}");
            }

View on GitHub (pinned to 777dd552ad)

Solutions

  1. Ensure the packaged app's start URL is a full web URL with a host (`https://example.com`), not `about:blank`, `data:`, or a bare scheme
  2. Guard the extraction: only install the auth delegate when `target_url.host_str()` is `Some`, otherwise skip delegate installation instead of panicking
  3. If custom-protocol URLs must be supported, derive the allow-list key from `target_url.scheme()` or the full URL string rather than `host_str()`
  4. Validate the URL early (at config/CLI parse time) so a hostless URL never reaches `build_window` as an auth target

Example fix

// before
let allowed_host = target_url
    .host_str()
    .expect("web URLs must have a host")
    .to_owned();
// after
let allowed_host = match target_url.host_str() {
    Some(host) => host.to_owned(),
    None => {
        log::warn!("auth target {target_url} has no host; skipping auth delegate");
        return;
    }
};
Defensive patterns

Strategy: validation

Validate before calling

fn is_web_url_with_host(s: &str) -> bool {
    matches!(url::Url::parse(s), Ok(u) if matches!(u.scheme(), "http" | "https") && u.host_str().is_some())
}
// validate the target before entering the auth flow

Type guard

fn web_host(url: &url::Url) -> Option<&str> {
    if matches!(url.scheme(), "http" | "https") {
        url.host_str()
    } else {
        None
    }
}

Try / catch

let Some(host) = target_url.host_str() else {
    log::warn!("no host on auth target {target_url}; skipping auth delegate");
    return;
};

Prevention

When it happens

Trigger: `auth_target` is `Some(...)` on macOS AND the target URL lacks a host — i.e. the URL passed to `build_window` (via `open_requested_window` / `build_window_with_label`) is a scheme-only or opaque URL such as `about:blank`, `data:text/html,...`, `javascript:...`, or a malformed string that still parsed but has no authority component.

Common situations: Developers hit this when packaging an app whose start URL is not an `http(s)` web URL (a `data:` or custom-scheme page), when a config file or CLI flag supplies an empty/scheme-only value that gets coerced into an auth flow, or when wiring basic-auth/certificate-error handling around a local file or custom-protocol URL that legitimately has no network host. It can also surface after refactors that widen which URLs set `auth_target`.

Related errors


AI-assisted analysis of tw93/Pake@777dd552ad (2026-09-05). Data as JSON: /api/errors/28fa07eedc0f50fb. Report an issue: GitHub.