From 36ae41a4f1b4201e05075711fbec34cf55bdf246 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Thu, 25 Sep 2025 07:53:41 +0800 Subject: [PATCH] FIX: Improve deleted file cleanup mechanism and prevent empty editor windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root Cause Analysis: - Generic error handling in main-axios.ts was stripping fileNotFound data from 404 responses - Windows were being created before error detection, showing empty editors with "File is empty" - Error message translation was not properly detecting various file-not-found scenarios Core Fixes: 1. **Preserve 404 Error Data:** Modified readSSHFile to preserve fileNotFound information - Create custom error object for 404 responses - Set isFileNotFound flag to bypass generic error handling - Maintain original response data for proper error detection 2. **Enhanced Error Detection:** Improved FileWindow error detection logic - Check for custom isFileNotFound flag - Detect multiple error message patterns: "File not found", "Resource not found" - Handle both backend-specific and generic error formats 3. **Prevent Empty Windows:** Auto-close window when file cleanup occurs - Call closeWindow(windowId) immediately after cleanup - Return early to prevent showing empty editor - Show only the cleanup notification toast Behavior Changes: - **Before:** Opens empty editor + shows "Server error occurred" + displays "File is empty" - **After:** Shows "File removed from recent/pinned lists" + closes window immediately - **Result:** Clean, user-friendly experience with automatic cleanup Technical Details: - Enhanced readSSHFile error handling for 404 status codes - Improved error pattern matching for various "not found" scenarios - Window lifecycle management during error states - Preserved backward compatibility for other error types 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .../Desktop/Apps/File Manager/components/FileWindow.tsx | 9 ++++++++- src/ui/main-axios.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ui/Desktop/Apps/File Manager/components/FileWindow.tsx b/src/ui/Desktop/Apps/File Manager/components/FileWindow.tsx index 09e6d5e5..e2622feb 100644 --- a/src/ui/Desktop/Apps/File Manager/components/FileWindow.tsx +++ b/src/ui/Desktop/Apps/File Manager/components/FileWindow.tsx @@ -200,16 +200,23 @@ export function FileWindow({ // Check if file not found (common error messages from cat command) const errorMessage = errorData?.error || error.message || "Unknown error"; const isFileNotFound = + (error as any).isFileNotFound || errorData?.fileNotFound || error.response?.status === 404 || + errorMessage.includes("File not found") || errorMessage.includes("No such file or directory") || errorMessage.includes("cannot access") || - errorMessage.includes("not found"); + errorMessage.includes("not found") || + errorMessage.includes("Resource not found"); if (isFileNotFound && onFileNotFound) { // Notify parent component about the missing file for cleanup onFileNotFound(file); toast.error(t("fileManager.fileNotFoundAndRemoved", { name: file.name })); + + // Close this window since the file doesn't exist + closeWindow(windowId); + return; // Exit early to prevent showing empty editor } else { toast.error(t("fileManager.failedToLoadFile", { error: errorMessage.includes("Server error occurred") ? diff --git a/src/ui/main-axios.ts b/src/ui/main-axios.ts index 52486737..243ed8b7 100644 --- a/src/ui/main-axios.ts +++ b/src/ui/main-axios.ts @@ -1051,7 +1051,14 @@ export async function readSSHFile( params: { sessionId, path }, }); return response.data; - } catch (error) { + } catch (error: any) { + // Preserve fileNotFound information for 404 errors + if (error.response?.status === 404) { + const customError = new Error("File not found"); + (customError as any).response = error.response; + (customError as any).isFileNotFound = error.response.data?.fileNotFound || true; + throw customError; + } handleApiError(error, "read SSH file"); } }