Repository navigation
fix: block tab creation on file open failure - #738
Conversation
Reviewer's GuideImplementationTreat any failure to open the requested file as a blocking error, show a warning, and return before creating a tab.
TestsUpdate the unreadable-file test to verify that the warning is shown and no tab is created.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 7 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**Missing files leave blank tabs**
When the requested supported path does not exist when `addTab` checks it, `fileInfo.exists()` skips the open-failure branch, so `Window::addTab` creates 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.
</issue_to_address>
### Comment 2
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 3
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**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`.
</issue_to_address>
### Comment 4
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 5
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 6
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**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.
</issue_to_address>
### Comment 7
<location path="src/widgets/window.cpp" line_range="720" />
<code_context>
if (testFile.open(QIODevice::ReadOnly)) {
testFile.close();
- } else if (testFile.error() == QFileDevice::PermissionsError) {
+ } else {
qCWarning(appLog) << "No permission to read file:" << filepath << "error:" << testFile.errorString();
QWidget *const msgParent = m_editorWidget->currentWidget() ? m_editorWidget->currentWidget() : this;
</code_context>
<issue_to_address>
**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.
</issue_to_address>| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟡 Medium · Missing files leave blank tabs
When the requested supported path does not exist when addTab checks it, fileInfo.exists() skips the open-failure branch, so Window::addTab creates 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
In `src/widgets/window.cpp` at line 720:
**Missing files leave blank tabs**
When the requested supported path does not exist when `addTab` checks it, `fileInfo.exists()` skips the open-failure branch, so `Window::addTab` creates 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.| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟡 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, 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.
Prompt for AI agents
In `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.| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `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`.| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `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.| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `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.| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟠 High · 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.
Prompt for AI agents
In `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.| if (testFile.open(QIODevice::ReadOnly)) { | ||
| testFile.close(); | ||
| } else if (testFile.error() == QFileDevice::PermissionsError) { | ||
| } else { |
There was a problem hiding this comment.
🟡 Medium · 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.
Prompt for AI agents
In `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.3b007d7 to
4c75728
Compare
1. Root cause: QFile::open returns OpenError(5) for permission-denied files, not PermissionsError(13); the else-if condition never matches 2. Fix: change else-if to else so any open failure shows a warning and returns, preventing tab creation 3. Impact: all file-open failure paths now properly block tab creation Influence: 1. Test opening files with read permission denied 2. Test opening normal readable files to verify no regression 3. Test opening non-existent files for error handling fix: 阻止文件打开失败时创建标签页 1. 根因:QFile::open 对权限不足文件返回 OpenError(5) 而非 PermissionsError(13),else-if 条件永不命中 2. 方案:将 else-if 改为 else,任何 open 失败均提示并 return 3. 影响:所有文件打开失败路径均正确阻止标签页创建 Influence: 1. 测试打开无读权限文件 2. 测试打开正常可读文件验证无回归 3. 测试打开不存在文件的错误处理 Log: fix blank tab created when opening files without permission Log: 修复打开无权限文件时创建空白标签页的问题 PMS: BUG-339655
4c75728 to
0bf3d6b
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: lzwind, pengfeixx The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
fix: block tab creation on file open failure
denied files, not PermissionsError(13); the else-if condition
never matches, falling through to create a blank tab
failure shows a warning and returns, preventing tab creation
creation; normal readable files are unaffected
Log: 修复打开无权限文件时创建空白标签页的问题
Influence:
fix: 修复打开无权限文件时创建空白标签页的问题
PermissionsError(13),else-if 条件永不命中,落入不 return
的分支导致创建空白标签页
失败均提示并 return,阻止标签页创建
Log: 修复打开无权限文件时创建空白标签页的问题
Influence:
PMS: BUG-339655
Summary by Sourcery
Block tab creation when opening a file fails while preserving normal file-opening behavior.
Bug Fixes:
Tests: