FIX: Improve deleted file cleanup mechanism and prevent empty editor windows
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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") ?
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user