rust-lang/rust-analyzer · error

Unable to write data

Error message

Unable to write data

What it means

After serializing the span record, the JSON profiling layer writes it to the configured writer and expects the write to succeed. A panic here means the underlying MakeWriter failed to write all bytes (I/O error), e.g. the profiling output file or pipe disappeared or is unwritable.

Source

Thrown at crates/rust-analyzer/src/tracing/json.rs:72

    fn on_event(&self, _event: &Event<'_>, _ctx: Context<'_, S>) {}

    fn on_close(&self, id: Id, ctx: Context<'_, S>) {
        #[derive(serde_derive::Serialize)]
        struct JsonDataInner {
            name: &'static str,
            elapsed_ms: u128,
        }

        let span = ctx.span(&id).unwrap();
        let Some(data) = span.extensions_mut().remove::<JsonData>() else {
            return;
        };

        let data = JsonDataInner { name: data.name, elapsed_ms: data.start.elapsed().as_millis() };
        let mut out = serde_json::to_string(&data).expect("Unable to serialize data");
        out.push('\n');
        self.writer.make_writer().write_all(out.as_bytes()).expect("Unable to write data");
    }
}

#[derive(Default, Clone, Debug)]
pub(crate) struct JsonFilter {
    pub(crate) allowed_names: Option<FxHashSet<String>>,
}

impl JsonFilter {
    pub(crate) fn from_spec(spec: &str) -> Self {
        let allowed_names = if spec == "*" {
            None
        } else {
            Some(FxHashSet::from_iter(spec.split('|').map(String::from)))
        };

        Self { allowed_names }
    }

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Ensure the profiling output destination is writable and has free space (check disk quota, df).
  2. Avoid piping profiling output to short-lived consumers; redirect to a file instead.
  3. Check the writer configuration (env/config for profiling output) points to a valid, accessible path.
  4. If scripting around rust-analyzer, keep the consuming process alive for the session.

Example fix

// before
rust-analyzer --profile-... | head -n 5   # pipe closes early -> panic
// after
rust-analyzer ... > /tmp/ra-profile.jsonl  # stable file target
Defensive patterns

Strategy: try-catch

Try / catch

if let Err(e) = self.writer.make_writer().write_all(out.as_bytes()) {
    eprintln!("profile write failed: {e}"); // degrade instead of panicking
}

Prevention

When it happens

Trigger: A span closes while the profiler is active and the writer's target (file, stderr, socket) returns an error or partial write: disk full, file handle closed, broken pipe when output is piped to a process that exited.

Common situations: Running rust-analyzer with profiling output redirected to a file on a full disk; profiling output piped to `head` or another short-lived consumer that closes the pipe; permissions changed on the output file mid-session.

Related errors


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