rust-lang/rust-analyzer · error
invalid profile depth
Error message
invalid profile depth
What it means
The hprof WriteFilter spec parser expects an optional '@N' suffix giving maximum profiling depth, parsed as usize. If the text after '@' is not a valid usize the expect panics with 'invalid profile depth'. Like the longer_than check, this is upfront validation of the profiling filter string.
Source
Thrown at crates/rust-analyzer/src/tracing/hprof.rs:243
#[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)))
};
(WriteFilter { depth, longer_than }, allowed)
}
}
#[allow(non_camel_case_types)]
struct ms(Duration);
impl std::fmt::Display for ms {View on GitHub (pinned to e8f7e90aa3)
Solutions
- Fix the spec so the '@' suffix is a valid depth integer, e.g. 'profile@3' limits depth to 3.
- Remove the '@' suffix entirely to use the default depth of 999.
- Check the env var for shell-quoting/interpolation issues that corrupt the value.
Example fix
// before RA_PROFILE="load@" // empty depth // after RA_PROFILE="load@5" // depth 5, or omit '@' for default
Defensive patterns
Strategy: validation
Validate before calling
fn validate_profile_depth(spec: &str) -> Result<(), String> {
if let Some(idx) = spec.rfind('@') {
spec[idx + 1..].parse::<usize>()
.map(|_| ())
.map_err(|_| format!("invalid depth suffix in {spec:?}"))
} else { Ok(()) }
} Prevention
- Use integer depths only after '@' (e.g. @3)
- Omit the '@' section to accept the default depth of 999
- Validate env values before launching rust-analyzer in scripts
When it happens
Trigger: Passing a profiling spec such as 'profile@x' or 'profile@' (empty after '@'), or a value exceeding usize range (e.g. '@99999999999999999999999'), through the profiling env/config.
Common situations: Typos in the depth portion of RA_PROFILE; shell interpolation replacing the number with empty or garbage; docs confusion between spec sections ('@' for depth vs '>' for duration).
Related errors
- invalid profile longer_than
- Memory profiling is not enabled for this build of rust-analy
- Please set `rust-analyzer.profiling.memoryProfile` to the pa
- Unable to serialize data
- Unable to write data
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/025a03c5f6acce10.
Report an issue: GitHub.