rust-lang/rust-analyzer · error

Unable to serialize args

Error message

Unable to serialize args

What it means

An `anyhow` error produced in `DiscoverCommand::spawn` while serializing the substituted discover-command arguments to JSON for the child process: one of the arguments templated into the command line failed to serialize. It is a guard around serde serialization of user-configured strings/paths; the input at fault is the `discover` command configuration being passed to the spawned process.

Source

Thrown at crates/rust-analyzer/src/discover.rs:58

    /// Create a new [DiscoverCommand].
    pub(crate) fn new(sender: Sender<DiscoverProjectMessage>, command: Vec<String>) -> Self {
        Self { sender, command }
    }

    /// Spawn the command inside `DiscoverCommand` and report progress, if any.
    pub(crate) fn spawn(
        &self,
        discover_arg: DiscoverArgument,
        current_dir: &Path,
    ) -> anyhow::Result<DiscoverHandle> {
        let command = &self.command[0];
        let args = &self.command[1..];

        let args: Vec<String> = args
            .iter()
            .map(|arg| {
                if arg == ARG_PLACEHOLDER {
                    serde_json::to_string(&discover_arg).expect("Unable to serialize args")
                } else {
                    arg.to_owned()
                }
            })
            .collect();

        // TODO: are we sure the extra env should be empty?
        let mut cmd = toolchain::command(command, current_dir, &FxHashMap::default());
        cmd.args(args);

        Ok(DiscoverHandle {
            handle: CommandHandle::spawn(cmd, DiscoverProjectParser, self.sender.clone(), None)?,
            span: info_span!("discover_command").entered(),
        })
    }
}

/// A handle to a spawned `DiscoverCommand`.

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Validate the `discover` command arguments in configuration (non-UTF8 paths or unsupported placeholder values)
  2. Check that the argument being templated (`{ARG_PLACEHOLDER}`-substituted) serializes as a plain JSON string
  3. Log the offending argument when serialization fails so the misconfigured entry can be identified
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/rust-analyzer/src/discover.rs:58 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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