{"record":{"id":"915e10f749aa596d","repo":"astral-sh/ruff","slug":"err","errorCode":null,"errorMessage":"{err}","messagePattern":"\\{err\\}","errorType":"error_code","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/ruff_server/src/server/api.rs","lineNumber":389,"sourceCode":"                }\n            })\n            .with_failure_code(server::ErrorCode::InternalError)?,\n    ))\n}\n\npub(crate) struct Error {\n    pub(crate) code: server::ErrorCode,\n    pub(crate) error: anyhow::Error,\n}\n\n/// A trait to convert result types into the server result type, [`super::Result`].\ntrait LSPResult<T> {\n    fn with_failure_code(self, code: server::ErrorCode) -> super::Result<T>;\n}\n\nimpl<T, E: Into<anyhow::Error>> LSPResult<T> for core::result::Result<T, E> {\n    fn with_failure_code(self, code: server::ErrorCode) -> super::Result<T> {\n        self.map_err(|err| Error::new(err.into(), code))\n    }\n}\n\nimpl Error {\n    fn new(err: anyhow::Error, code: server::ErrorCode) -> Self {\n        Self { code, error: err }\n    }\n}\n\n// Right now, we treat the error code as invisible data that won't\n// be printed.\nimpl std::fmt::Debug for Error {\n    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {\n        self.error.fmt(f)\n    }\n}\n\nimpl std::fmt::Display for Error {","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ruff_server/src/server/api.rs#L371-L407","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the inner `{err}` text in the LSP error response — it identifies the actual failing operation.","Fix the underlying condition the inner message describes (config, document state, range validity).","Check the server logs (the request path logs warnings/errors) for the full anyhow chain.","If developing ruff, prefer mapping known failures to specific error codes instead of the generic path."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Client: wrap every LSP request and inspect the error's message payload for the inner cause\ntry {\n  return await connection.sendRequest(method, params)\n} catch (err) {\n  log.error(`LSP ${method} failed: ${err.message}`) // message == inner anyhow Display text\n  return fallbackValue\n}","preventionTips":["Read the inner `{err}` text — it names the failing operation.","Validate document/range parameters before dispatching requests.","Check server logs for the full anyhow error chain."],"tags":["lsp","anyhow","error-handling","server"],"backgroundTag":"lsp-request-failed","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"}