astral-sh/ruff · error · Error

{err}

Error message

{err}

What it means

`with_failure_code` is a helper trait method on `Result` in the ruff server that converts any inner error into the server's LSP `Error` type while attaching a specific JSON-RPC error code. The resulting message is simply the anyhow error's Display output (`{err}`), so this entry represents any error surfaced through this path — its text is whatever the underlying failure prints.

Source

Thrown at crates/ruff_server/src/server/api.rs:389

                }
            })
            .with_failure_code(server::ErrorCode::InternalError)?,
    ))
}

pub(crate) struct Error {
    pub(crate) code: server::ErrorCode,
    pub(crate) error: anyhow::Error,
}

/// A trait to convert result types into the server result type, [`super::Result`].
trait LSPResult<T> {
    fn with_failure_code(self, code: server::ErrorCode) -> super::Result<T>;
}

impl<T, E: Into<anyhow::Error>> LSPResult<T> for core::result::Result<T, E> {
    fn with_failure_code(self, code: server::ErrorCode) -> super::Result<T> {
        self.map_err(|err| Error::new(err.into(), code))
    }
}

impl Error {
    fn new(err: anyhow::Error, code: server::ErrorCode) -> Self {
        Self { code, error: err }
    }
}

// Right now, we treat the error code as invisible data that won't
// be printed.
impl std::fmt::Debug for Error {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.error.fmt(f)
    }
}

impl std::fmt::Display for Error {

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Read the inner `{err}` text in the LSP error response — it identifies the actual failing operation.
  2. Fix the underlying condition the inner message describes (config, document state, range validity).
  3. Check the server logs (the request path logs warnings/errors) for the full anyhow chain.
  4. If developing ruff, prefer mapping known failures to specific error codes instead of the generic path.
Defensive patterns

Strategy: try-catch

Try / catch

// Client: wrap every LSP request and inspect the error's message payload for the inner cause
try {
  return await connection.sendRequest(method, params)
} catch (err) {
  log.error(`LSP ${method} failed: ${err.message}`) // message == inner anyhow Display text
  return fallbackValue
}

Prevention

When it happens

Trigger: Any `Result` inside the ruff server's API layer is wrapped with `.with_failure_code(code)`, e.g. when a request handler (hover, formatting, diagnostics) fails internally and the server maps the failure to an LSP error like InternalError or RequestFailed with the inner error's message as the payload.

Common situations: Malformed document state causing a handler panic/Err; failing to apply a workspace edit; IO errors reading config during a request; internal invariant violations inside a request task.

Related errors


AI-assisted analysis of astral-sh/ruff@26f38c119c (2026-09-05). Data as JSON: /api/errors/915e10f749aa596d. Report an issue: GitHub.