GitoxideLabs/gitoxide · error

host is present in url

Error message

host is present in url

What it means

Panic from `url.host().expect("host is present in url")` while establishing an async TCP (`git://`) connection in gix-transport. The library assumes any URL using a scheme that reaches this branch (git protocol) carries a host, because URL parsing normally enforces it. If the host is somehow absent the connection setup panics rather than returning a parse error.

Solutions

  1. Use a well-formed URL including a host, e.g. `git://example.com/repo.git`.
  2. Validate the URL before connecting (parse it and check `host()` is `Some`).
  3. Prefer cloning from the remote's advertised URL rather than retyping it.
  4. Upgrade gix-transport/gix in case parsing has changed to allow host-less git URLs.

Example fix

// before
let remote = repo.remote("origin").url().expect(...); // "git:///repo.git" (no host)
// after
assert url starts with "git://" and has a non-empty host before connect:
let parsed = gix_url::parse(url.as_bytes())?;
assert!(parsed.host.is_some(), "git URLs require a host");
Defensive patterns

Strategy: validation

Validate before calling

let parsed = gix_url::parse(url.as_bytes())?;
if parsed.host.is_none() {
    anyhow::bail!("git:// URL requires a host: {url}");
}

Type guard

fn has_host(u: &gix_url::Url) -> bool {
    u.host.is_some()
}

Try / catch

match std::panic::catch_unwind(AssertUnwindSafe(|| connect(url))) {
    Ok(c) => c,
    Err(_) => anyhow::bail!("connect panicked: URL missing host"),
}

Prevention

When it happens

Trigger: Calling `gix::protocol::connect` (async) with a `git://` URL whose host component is empty or missing, e.g. `git://` or `git:///path`, slipping past validation.

Common situations: Hand-built or truncated remote URLs in configuration; programmatic URL construction that omits the host; unusual URL forms that parsers did not reject.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


AI-assisted analysis of GitoxideLabs/gitoxide@e73179060b (2026-09-08). Data as JSON: /api/errors/9ac271995315fc27. Report an issue: GitHub.

Appendix: source

Thrown at gix-transport/src/client/async_io/connect.rs:30

    /// Use `options` to further control specifics of the transport resulting from the connection.
    pub async fn connect<Url, E>(url: Url, options: super::Options) -> Result<Box<dyn Transport + Send>, Error>
    where
        Url: TryInto<gix_url::Url, Error = E>,
        gix_url::parse::Error: From<E>,
    {
        let mut url = url.try_into().map_err(gix_url::parse::Error::from)?;
        Ok(match url.scheme {
            gix_url::Scheme::Git => {
                if url.user().is_some() {
                    return Err(Error::UnsupportedUrlTokens {
                        url: url.to_bstring(),
                        scheme: url.scheme,
                    });
                }
                let path = std::mem::take(&mut url.path);
                Box::new(
                    Connection::new_tcp(
                        url.host().expect("host is present in url"),
                        url.port,
                        path,
                        options.version,
                        options.trace,
                    )
                    .await
                    .map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)?,
                )
            }
            scheme => return Err(Error::UnsupportedScheme(scheme)),
        })
    }
}

#[cfg(feature = "async-std")]
pub use function::connect;

View on GitHub (pinned to e73179060b)