astral-sh/ruff · error

InternalError

InternalError

Error message

Request handler failed with: {panic_message}

What it means

When a request handler task panics, the server catches it (panic hook) and converts the panic into an LSP InternalError (-32603) response whose message is `Request handler failed with: {panic_message}`. It wraps arbitrary server bugs so the connection survives, but signals a real defect in the handler.

Source

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

        Box<dyn std::any::Any + Send + 'static>,
    >,
) -> Result<<<R as RequestHandler>::RequestType as Request>::Result>
where
    R: RequestHandler,
{
    match result {
        Ok(response) => response,

        Err(error) => {
            let message = if let Some(panic_message) = panic_message(&error) {
                format!("Request handler failed with: {panic_message}")
            } else {
                "Request handler failed".into()
            };

            Err(Error {
                code: lsp_server::ErrorCode::InternalError,
                error: anyhow!(message),
            })
        }
    }
}

fn sync_notification_task<N: SyncNotificationHandler>(notif: server::Notification) -> Result<Task> {
    let (id, params) = cast_notification::<N>(notif)?;
    Ok(Task::sync(move |session, client| {
        let _span = tracing::debug_span!("notification", method = %N::METHOD).entered();
        if let Err(err) = N::run(session, client, params) {
            tracing::error!("An error occurred while running {id}: {err}");
            client
                .show_error_message("Ruff encountered a problem. Check the logs for more details.");
        }
    }))
}

#[expect(dead_code)]

View on GitHub (pinned to 26f38c119c)

Solutions

  1. Capture the panic message and request method from server logs and search/report it on the Ruff issue tracker
  2. Update Ruff to the latest version — handler panics are bugs that get fixed
  3. Identify the triggering document/request and provide a minimal reproduction in the report
  4. Restart the server after the panic; the failed request can be retried but will recur until the bug is fixed

Example fix

// before (handler)
let ch = line.chars().nth(offset).unwrap();
// after
let ch = line.chars().nth(offset)
    .ok_or_else(|| anyhow::anyhow!("offset {offset} out of range"))?;
Defensive patterns

Strategy: try-catch

Try / catch

// Client (TypeScript)
try {
  await client.sendRequest('textDocument/codeAction', params);
} catch (e) {
  if (e.code === -32603 && /Request handler failed/.test(e.message)) {
    logBugReportContext(e.message); // include method + params in Ruff issue
    await restartRuffServer();
  } else throw e;
}

Prevention

When it happens

Trigger: Any request handler panicking — index out of bounds, failed unwrap/expect, assertion, or explicit panic — during handling of a client request.

Common situations: Edge-case input triggering an unwrap in a handler (malformed document positions, race between didChange and requests); bugs in a specific Ruff version; running against unusual files (huge notebooks, invalid syntax).

Related errors


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