{"record":{"id":"14084b809a69f2b2","repo":"astral-sh/ruff","slug":"internalerror-14084b","errorCode":"InternalError","errorMessage":"Request handler failed with: {panic_message}","messagePattern":"Request handler failed with: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/ruff_server/src/server/api.rs","lineNumber":222,"sourceCode":"        Box<dyn std::any::Any + Send + 'static>,\n    >,\n) -> Result<<<R as RequestHandler>::RequestType as Request>::Result>\nwhere\n    R: RequestHandler,\n{\n    match result {\n        Ok(response) => response,\n\n        Err(error) => {\n            let message = if let Some(panic_message) = panic_message(&error) {\n                format!(\"Request handler failed with: {panic_message}\")\n            } else {\n                \"Request handler failed\".into()\n            };\n\n            Err(Error {\n                code: lsp_server::ErrorCode::InternalError,\n                error: anyhow!(message),\n            })\n        }\n    }\n}\n\nfn sync_notification_task<N: SyncNotificationHandler>(notif: server::Notification) -> Result<Task> {\n    let (id, params) = cast_notification::<N>(notif)?;\n    Ok(Task::sync(move |session, client| {\n        let _span = tracing::debug_span!(\"notification\", method = %N::METHOD).entered();\n        if let Err(err) = N::run(session, client, params) {\n            tracing::error!(\"An error occurred while running {id}: {err}\");\n            client\n                .show_error_message(\"Ruff encountered a problem. Check the logs for more details.\");\n        }\n    }))\n}\n\n#[expect(dead_code)]","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_server/src/server/api.rs#L204-L240","documentation":"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.","triggerScenarios":"Any request handler panicking — index out of bounds, failed unwrap/expect, assertion, or explicit panic — during handling of a client request.","commonSituations":"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).","solutions":["Capture the panic message and request method from server logs and search/report it on the Ruff issue tracker","Update Ruff to the latest version — handler panics are bugs that get fixed","Identify the triggering document/request and provide a minimal reproduction in the report","Restart the server after the panic; the failed request can be retried but will recur until the bug is fixed"],"exampleFix":"// before (handler)\nlet ch = line.chars().nth(offset).unwrap();\n// after\nlet ch = line.chars().nth(offset)\n    .ok_or_else(|| anyhow::anyhow!(\"offset {offset} out of range\"))?;","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Client (TypeScript)\ntry {\n  await client.sendRequest('textDocument/codeAction', params);\n} catch (e) {\n  if (e.code === -32603 && /Request handler failed/.test(e.message)) {\n    logBugReportContext(e.message); // include method + params in Ruff issue\n    await restartRuffServer();\n  } else throw e;\n}","preventionTips":["Update Ruff promptly — handler panics are fixed bugs","Save the panic message and request that triggered it for issue reports","Test the server against your project's unusual files (big notebooks, edge syntax)","Avoid partial/rapid didChange floods that can race document state in older versions"],"tags":["rust","lsp","server","panic","internal-error"],"backgroundTag":"request-handler-panicked","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}