{"record":{"id":"3d3676cef6f1371a","repo":"sinelaw/fresh","slug":"preview-split-does-not-exist","errorCode":null,"errorMessage":"preview: split {:?} does not exist","messagePattern":"preview: split (.+?) does not exist","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fresh-editor/src/app/buffer_management.rs","lineNumber":290,"sourceCode":"        column: Option<usize>,\n    ) -> anyhow::Result<BufferId> {\n        let previous_split = self\n            .windows\n            .get(&self.active_window)\n            .and_then(|w| w.buffers.splits())\n            .map(|(mgr, _)| mgr.active_split())\n            .ok_or_else(|| anyhow::anyhow!(\"no split layout\"))?;\n\n        let set_active = |editor: &mut Self, split: LeafId| -> bool {\n            editor\n                .windows\n                .get_mut(&editor.active_window)\n                .and_then(|w| w.split_manager_mut())\n                .is_some_and(|mgr| mgr.set_active_split(split))\n        };\n\n        if !set_active(self, target_split) {\n            anyhow::bail!(\"preview: split {:?} does not exist\", target_split);\n        }\n\n        let result = self.preview_file(path);\n        if result.is_ok() && (line.is_some() || column.is_some()) {\n            self.jump_to_line_column(line, column);\n        }\n\n        // Back to where the user actually is. `previous_split` was live a\n        // moment ago; if the open collapsed it (it cannot — a preview open\n        // adds a buffer, it doesn't close splits) the id simply won't set.\n        set_active(self, previous_split);\n\n        result\n    }\n\n    /// Drop the current preview tab, if any: the browse is over and was not\n    /// committed. Closes the preview buffer so the split falls back to what\n    /// it was showing before.","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/sinelaw/fresh/blob/67894ca5463dbd7a89bb31add4627c27d6b79d83/crates/fresh-editor/src/app/buffer_management.rs#L272-L308","documentation":"preview_file_in_split fails when the requested split id cannot be found in the active window's split manager, so set_active_split returns false. The editor refuses to activate a preview in a split that no longer exists rather than silently previewing elsewhere.","triggerScenarios":"Calling preview_file_in_split (via handle_preview_file_in_split) with a target_split id that was closed, was never created, or belongs to a different window than the currently active window.","commonSituations":"A plugin or keybinding caches a split id, the user closes that split, then triggers a preview; switching active windows so the cached id isn't valid in the new window's split manager.","solutions":["Re-resolve the split id from the active window's split manager before calling preview_file_in_split.","Check that the split still exists (e.g. view_states/split list contains the id) and bail gracefully with a user message instead of erroring.","Fall back to preview_file in the current split when the target split is missing."],"exampleFix":"// before\neditor.preview_file_in_split(&path, stale_split_id, None, None)?;\n// after\nif editor.split_exists(stale_split_id) {\n    editor.preview_file_in_split(&path, stale_split_id, None, None)?;\n} else {\n    editor.preview_file(&path)?;\n}","handlingStrategy":"validation","validationCode":"if !editor.split_exists(target_split) { return; } // check before preview_file_in_split","typeGuard":"fn split_exists(editor: &Editor, id: SplitId) -> bool { editor.active_window_splits().map_or(false, |s| s.contains(&id)) }","tryCatchPattern":"match editor.preview_file_in_split(&path, target_split, line, column) { Err(e) if e.to_string().contains(\"does not exist\") => editor.preview_file(&path), r => r }","preventionTips":["Never cache split ids across layout changes; resolve them per invocation","Check the active window before targeting a split","Fall back to the current split on missing targets"],"tags":["editor","split-layout","invalid-identifier"],"backgroundTag":"entity-not-found","analyzedSha":"67894ca5463dbd7a89bb31add4627c27d6b79d83","analyzedAt":"2026-09-13T15:04:03.701Z","contentChangedAt":"2026-09-13T15:04:03.701Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}