Repository navigation
fix: block tab creation on file open failure #738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -717,14 +717,12 @@ void Window::addTab(const QString &filepath, bool activeTab) | |
| QFile testFile(filepath); | ||
| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Failed loads leave blank tabs When the file is removed or becomes unreadable after the probe succeeds but before the asynchronous load opens it, Handle asynchronous load failures by removing or rejecting the tab and wrapper instead of leaving an empty tab. Prompt for AI agentsIn `src/widgets/window.cpp` at line 720:
**Failed loads leave blank tabs**
When the file is removed or becomes unreadable after the probe succeeds but before the asynchronous load opens it, `Window::addTab` commits the tab after closing the probe file, then `FileLoadThread` fails to open the path and the load-failure handler leaves the editor empty; the caller sees a blank tab.
Handle asynchronous load failures by removing or rejecting the tab and wrapper instead of leaving an empty tab.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Open errors get wrong explanation When an existing supported file fails to open for a reason other than insufficient permissions, Use the permission-specific log and message only for Also at Prompt for AI agentsIn `src/widgets/window.cpp` at line 720:
**Open errors get wrong explanation**
When an existing supported file fails to open for a reason other than insufficient permissions, `addTab` routes every `QFile::open` failure through the permission-specific log and message, so callers are told they lack permission even when another I/O error caused the failure.
Use the permission-specific log and message only for `PermissionsError`, and report other open failures with an appropriate generic error.
Also at `src/widgets/window.cpp:721-724`.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Existing document is not activated When a file already open in another window becomes unreadable before the user opens it again, Check for and activate an already-open path before returning on a failed read probe. Prompt for AI agentsIn `src/widgets/window.cpp` at line 720:
**Existing document is not activated**
When a file already open in another window becomes unreadable before the user opens it again, `addTab` returns on the failed open before `StartManager::checkPath` can find and activate the existing tab, so the user sees a warning instead of the existing document and its loaded or unsaved content.
Check for and activate an already-open path before returning on a failed read probe.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Pending files bypass read check When a multi-file selection includes an unreadable supported file after the first file, Apply the open check to files before creating pending tabs. Prompt for AI agentsIn `src/widgets/window.cpp` at line 720:
**Pending files bypass read check**
When a multi-file selection includes an unreadable supported file after the first file, `Window::openFile` sends later files through `addPendingTab`, which bypasses the open check; activating the placeholder later starts a load that fails and leaves an empty tab.
Apply the open check to files before creating pending tabs.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟠 High · Unreadable-file test fails When the window tests run as a non-root user where the test file's permission bits prevent reading, Update the test to expect the warning and the absence of a tab under enforced unreadable-file permissions. Prompt for AI agentsIn `src/widgets/window.cpp` at line 720:
**Unreadable-file test fails**
When the window tests run as a non-root user where the test file's permission bits prevent reading, `addTab` now warns and returns without creating a tab, but `AddTab_UnreadableFile_OpenFailsWithGenericError_Continues` expects no warning and one tab, so the test fails.
Update the test to expect the warning and the absence of a tab under enforced unreadable-file permissions.There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium · Failed opens leave empty windows When an unreadable file is opened through the new-window route, Have the caller detect a failed open and close or avoid showing the newly created window. Prompt for AI agentsIn `src/widgets/window.cpp` at line 720:
**Failed opens leave empty windows**
When an unreadable file is opened through the new-window route, `StartManager::openFilesInWindow` creates and shows a window before calling `Window::addTab`; when the new early return prevents the tab from being added, the `void` call gives the caller no way to close that window. Opening an unreadable file in this route leaves an empty window visible.
Have the caller detect a failed open and close or avoid showing the newly created window. |
||
| qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString(); | ||
| QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this; | ||
| DMessageManager::instance()->sendMessage(msgParent, QIcon(":/images/warning.svg"), | ||
| QString(tr("You do not have permission to open %1")).arg(filepath)); | ||
| return; | ||
| } else { | ||
| qCWarning(appLog) << "Failed to open file:" << filepath << "error:" << testFile.errorString(); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium · Missing files leave blank tabs
When the requested supported path does not exist when
addTabchecks it,fileInfo.exists()skips the open-failure branch, soWindow::addTabcreates a tab and starts loading the missing path; the load failure leaves the user with a blank tab.Reject missing paths before creating the tab, rather than skipping the open check when
fileInfo.exists()is false.Prompt for AI agents