{"record":{"id":"745436363258c521","repo":"astral-sh/ruff","slug":"server-notebook-document-could-not-be-converted-to","errorCode":null,"errorMessage":"Server notebook document could not be converted to ty's notebook document format: {err}","messagePattern":"Server notebook document could not be converted to ty's notebook document format: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/ty_server/src/document/notebook.rs","lineNumber":128,"sourceCode":"                        }))\n                    }\n                    NotebookCellKind::Custom(_) => {\n                        // Ignore unsupported cell kinds. This arm should never be reached unless a\n                        // client sends a value which is not mentioned/supported in the LSP.\n                        None\n                    }\n                }\n            })\n            .collect();\n        let raw_notebook = ruff_notebook::RawNotebook {\n            cells,\n            metadata: self.metadata.clone(),\n            nbformat: 4,\n            nbformat_minor: 5,\n        };\n\n        ruff_notebook::Notebook::from_raw_notebook(raw_notebook, false).unwrap_or_else(|err| {\n            panic!(\n                \"Server notebook document could not be converted to ty's \\\n                notebook document format: {err}\"\n            )\n        })\n    }\n\n    pub(crate) fn update(\n        &mut self,\n        array: lsp_types::NotebookCellArrayChange,\n        updated_cells: Vec<lsp_types::NotebookCell>,\n        metadata_change: Option<serde_json::Map<String, serde_json::Value>>,\n        version: DocumentVersion,\n    ) -> crate::Result<()> {\n        self.version = version;\n\n        let new_cells = array.cells.unwrap_or_default();\n        let start = array.start as usize;\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/astral-sh/ruff/blob/26f38c119cac42e4d320ba08f09224fdec74af2c/crates/ty_server/src/document/notebook.rs#L110-L146","documentation":"When converting a server-side notebook document into ruff_notebook's Notebook format, `Notebook::from_raw_notebook` failed (e.g. invalid cell structure or malformed nbformat fields). The code in `to_ruff_notebook` cannot recover from this and panics with this message including the underlying conversion error. It indicates the LSP client sent a notebook document whose raw JSON does not satisfy nbformat v4 requirements.","triggerScenarios":"Opening or syncing a .ipynb document in the editor when the client-provided notebook JSON is structurally invalid: missing or malformed cells/cell ids, invalid source types, or an nbformat version mismatch, causing from_raw_notebook to return Err inside NotebookDocument::to_ruff_notebook.","commonSituations":"Editor extensions or third-party LSP clients that construct notebook documents by hand rather than from a real .ipynb file; notebooks from older/newer nbformat versions with unsupported fields; corrupted notebook state after a failed save or plugin transformation.","solutions":["Validate the notebook JSON on the client side (nbformat validate) before opening/sending it to ty's language server.","Check the {err} detail in the panic message to identify the offending cell or field and fix it in the .ipynb file.","Reopen or reload the notebook from disk to resync the document with the server.","If a specific client produces this, report/fix the client's notebook serialization to conform to nbformat 4.x."],"exampleFix":"// before: hand-built notebook JSON with a cell missing its id\n{\"cells\":[{\"cell_type\":\"code\",\"source\":\"x = 1\"}],\"nbformat\":4}\n// after: valid nbformat 4.5 notebook with required ids\n{\"cells\":[{\"cell_type\":\"code\",\"id\":\"cell-1\",\"metadata\":{},\"source\":\"x = 1\",\"outputs\":[],\"execution_count\":null}],\"metadata\":{},\"nbformat\":4,\"nbformat_minor\":5}","handlingStrategy":"validation","validationCode":"// Validate the .ipynb JSON before opening it in the client:\nconst nb = JSON.parse(notebookJson);\nif (nb.nbformat !== 4 || !Array.isArray(nb.cells)) throw new Error('unsupported nbformat');\nfor (const cell of nb.cells) {\n  if (!['code', 'markdown', 'raw'].includes(cell.cell_type)) throw new Error('bad cell_type');\n  if (nb.nbformat_minor >= 5 && !cell.id) throw new Error('missing cell id');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only open notebooks produced by real .ipynb serialization (nbformat-compliant).","Validate notebooks with nbformat before syncing them to the LSP.","Avoid hand-rolling notebook JSON in editor extensions."],"tags":["notebook","lsp","panic","jupyter","serde"],"backgroundTag":"invalid-notebook-format","analyzedSha":"26f38c119cac42e4d320ba08f09224fdec74af2c","analyzedAt":"2026-09-05T10:32:37.492Z","contentChangedAt":"2026-09-05T10:32:37.492Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}