{"record":{"id":"efe8d7273679b1ea","repo":"GraphiteEditor/Graphite","slug":"tried-to-render-non-existent-document","errorCode":null,"errorMessage":"Tried to render non-existent document","messagePattern":"Tried to render non-existent document","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"editor/src/messages/portfolio/portfolio_message_handler.rs","lineNumber":1444,"sourceCode":"\t\t\t\t\twarn!(\"Tried to read non existent document\");\n\t\t\t\t\treturn;\n\t\t\t\t};\n\t\t\t\tif !document.is_loaded {\n\t\t\t\t\tdocument.is_loaded = true;\n\t\t\t\t\tresponses.add(PortfolioMessage::ResolveDocumentResources { document_id });\n\t\t\t\t\tresponses.add(PortfolioMessage::UpdateDocumentWidgets);\n\t\t\t\t\tresponses.add(PropertiesPanelMessage::Clear);\n\t\t\t\t}\n\t\t\t}\n\t\t\tPortfolioMessage::SubmitDocumentExport {\n\t\t\t\tname,\n\t\t\t\tfile_type,\n\t\t\t\tscale_factor,\n\t\t\t\tbounds,\n\t\t\t\tartboard_name,\n\t\t\t\tartboard_count,\n\t\t\t} => {\n\t\t\t\tlet document_id = self.active_document_id.expect(\"Tried to render non-existent document\");\n\t\t\t\tlet document = self.documents.get_mut(&document_id).expect(\"Tried to render non-existent document\");\n\t\t\t\tlet export_config = ExportConfig {\n\t\t\t\t\tname,\n\t\t\t\t\tfile_type,\n\t\t\t\t\tscale_factor,\n\t\t\t\t\tbounds,\n\t\t\t\t\tartboard_name,\n\t\t\t\t\tartboard_count,\n\t\t\t\t\t..Default::default()\n\t\t\t\t};\n\t\t\t\tlet result = self.executor.submit_document_export(document, document_id, export_config);\n\n\t\t\t\tif let Err(description) = result {\n\t\t\t\t\tresponses.add(DialogMessage::DisplayDialogError {\n\t\t\t\t\t\ttitle: \"Unable to export document\".to_string(),\n\t\t\t\t\t\tdescription,\n\t\t\t\t\t});\n\t\t\t\t}","sourceCodeStart":1426,"sourceCodeEnd":1462,"githubUrl":"https://github.com/GraphiteEditor/Graphite/blob/c507b356453361e31638b8bff8f6d46b6da2961e/editor/src/messages/portfolio/portfolio_message_handler.rs#L1426-L1462","documentation":"Handling PortfolioMessage::SubmitDocumentExport does self.active_document_id.expect(\"Tried to render non-existent document\") (and a second expect on documents.get_mut). The export pipeline assumes an active document exists when the frontend submits export settings; the expect panics when the message arrives with active_document_id == None - i.e., all documents are closed or none was ever activated. This is a classic message/race desync: the export dialog callback can land after the document it targets was closed.","triggerScenarios":"Frontend sends SubmitDocumentExport (Export menu, artboard export) while no document is open - e.g., the document was closed between opening the export dialog and clicking Export, or during shutdown/initialization.","commonSituations":"User closes the last document with the export dialog still open; export request races session teardown or document switching; frontend state allowing the export button when the editor has no documents.","solutions":["Guard with let Some(document_id) = self.active_document_id else { log and return } before touching the export executor","Disable/hide the export UI on the frontend when the document list is empty","Have the frontend cancel in-flight export dialogs on document close so stale submits never reach the handler"],"exampleFix":"// before\nlet document_id = self.active_document_id.expect(\"Tried to render non-existent document\");\n\n// after\nlet Some(document_id) = self.active_document_id else {\n\tlog::error!(\"SubmitDocumentExport with no active document\");\n\treturn;\n};","handlingStrategy":"validation","validationCode":"// frontend/guard before submitting export\n// if (!editor.hasActiveDocument()) return;\n\n// handler-side\nif self.active_document_id.is_none() || self.documents.is_empty() {\n\tlog::error!(\"ignoring SubmitDocumentExport with no open document\");\n\treturn;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Disable the Export UI whenever the open-document list becomes empty","Cancel or consume pending export dialogs when the active document changes or closes","Validate active_document_id and documents.contains_key before starting any export work"],"tags":["rust","message-handler","export","optional-state","race-condition"],"backgroundTag":"missing-active-document","analyzedSha":"c507b356453361e31638b8bff8f6d46b6da2961e","analyzedAt":"2026-08-16T21:57:18.596Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}