epi052/feroxbuster · error · anyhow::Error

No path segments found

Error message

No path segments found

What it means

FeroxUrl::depth computes a target's path depth by splitting its path into segments. After parsing with parse_url_with_raw_path it calls path_segments(); since that returns None for URLs without a hierarchical path component (cannot-be-a-base URLs), the code bails with 'No path segments found'.

Solutions

  1. Use an http/https URL with a normal path when calling depth()
  2. Filter non-hierarchical schemes out of the target list before computing depth
  3. Handle the anyhow error at the call site (ordered_scan_url / reached_max_depth) and skip the offending URL

Example fix

// before
let d = FeroxUrl::new("mailto:user@example.com", 1)?.depth()?;
// after
if url.starts_with("http") { let d = ferox_url.depth()?; }
Defensive patterns

Strategy: type-guard

Validate before calling

fn has_path_segments(u: &url::Url) -> bool { u.path_segments().map(|_| true).unwrap_or(false) }

Type guard

fn is_hierarchical_http(s: &str) -> bool { url::Url::parse(s).ok().map(|u| matches!(u.scheme(), "http"|"https") && u.path_segments().is_some()).unwrap_or(false) }

Try / catch

match ferox_url.depth() { Err(e) if e.to_string().contains("No path segments") => skip_url(url), Err(e) => return Err(e), Ok(d) => use_depth(d) }

Prevention

When it happens

Trigger: Calling .depth() on a URL that url::Url parses as cannot-be-a-base — opaque URLs like 'mailto:a@b' or 'data:text/plain,hi' have no path segments and trigger the error; normal http(s) URLs (even empty paths) yield segments.

Common situations: Feeding non-HTTP schemes (mailto:, data:) into scan-url handling or recursion-depth checks via a target list containing such entries.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of epi052/feroxbuster@1f595dab5c (2026-09-13). Data as JSON: /api/errors/d28ea6adae860192. Report an issue: GitHub.

Appendix: source

Thrown at src/url.rs:272

    ///
    /// Essentially looks at the Url path and determines how many directories are present in the
    /// given Url
    ///
    /// http://localhost -> 1
    /// http://localhost/ -> 1
    /// http://localhost/stuff -> 2
    /// ...
    ///
    /// returns 0 on error and relative urls
    pub fn depth(&self) -> Result<usize> {
        log::trace!("enter: get_depth");

        let target = self.normalize();

        let parsed = parse_url_with_raw_path(&target)?;
        let parts = parsed
            .path_segments()
            .ok_or_else(|| anyhow!("No path segments found"))?;

        // at least an empty string returned by the Split, meaning top-level urls
        let mut depth = 0;

        for _ in parts {
            depth += 1;
        }

        log::trace!("exit: get_depth -> {depth}");
        Ok(depth)
    }
}

/// Display implementation for a FeroxUrl
impl fmt::Display for FeroxUrl {
    /// formatter for FeroxUrl
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "{}", self.target)

View on GitHub (pinned to 1f595dab5c)