rust-lang/rust-analyzer · error

invalid profile longer_than

Error message

invalid profile longer_than

What it means

rust-analyzer's hprof profiling WriteFilter parses a spec string whose trailing '>' segment is the minimum span duration in milliseconds. If that segment cannot be parsed as an unsigned integer, the expect panics with 'invalid profile longer_than'. This is an input-format validation guard on the profiling filter spec (e.g. PROFILE_TO or similar env-provided spec).

Source

Thrown at crates/rust-analyzer/src/tracing/hprof.rs:235

            }
        }
        self.children.truncate(idx + 1);
        for child in &mut self.children {
            child.aggregate()
        }
    }
}

#[derive(Default, Clone, Debug)]
pub(crate) struct WriteFilter {
    depth: usize,
    longer_than: Duration,
}

impl WriteFilter {
    pub(crate) fn from_spec(mut spec: &str) -> (WriteFilter, Option<FxHashSet<String>>) {
        let longer_than = if let Some(idx) = spec.rfind('>') {
            let longer_than = spec[idx + 1..].parse().expect("invalid profile longer_than");
            spec = &spec[..idx];
            Duration::from_millis(longer_than)
        } else {
            Duration::new(0, 0)
        };

        let depth = if let Some(idx) = spec.rfind('@') {
            let depth: usize = spec[idx + 1..].parse().expect("invalid profile depth");
            spec = &spec[..idx];
            depth
        } else {
            999
        };
        let allowed = if spec == "*" {
            None
        } else {
            Some(FxHashSet::from_iter(spec.split('|').map(String::from)))
        };

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Correct the spec so the part after '>' is a plain integer of milliseconds, e.g. 'profile*>50' means spans longer than 50ms.
  2. Verify the environment variable / config value with `env | grep PROFILE` (or the relevant setting) and fix quoting or truncation.
  3. Consult rust-analyzer tracing docs for the filter grammar: name[@depth][>ms].

Example fix

// before
RA_PROFILE="*/3>1s>"       // trailing '>' with no number
// after
RA_PROFILE="*/3>1000"     // spans longer than 1000 ms
Defensive patterns

Strategy: validation

Validate before calling

fn validate_profile_spec(spec: &str) -> Result<(), String> {
    if let Some(idx) = spec.rfind('>') {
        spec[idx + 1..].parse::<u64>()
            .map(|_| ())
            .map_err(|_| format!("invalid longer_than suffix in {spec:?}"))
    } else { Ok(()) }
}

Prevention

When it happens

Trigger: Setting the profiling spec with a '>' suffix whose part after '>' is not a valid integer, e.g. 'profile_name>abc' or an empty suffix 'name>' passed via the profiling filter config/env.

Common situations: Typos in the RA_PROFILE env var value (e.g. '...>10m' or '...>ten-ms'); shell quoting mangling the spec so trailing characters get cut; copy-pasting a spec with a trailing '>' but no number.

Related errors


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/56c4a62bc56701fd. Report an issue: GitHub.