Skip to content

fix: clean up session and UI when driver plugin is missing on connect#297

Merged
datlechin merged 2 commits intomainfrom
fix/missing-plugin-connection-stuck
Mar 12, 2026
Merged

fix: clean up session and UI when driver plugin is missing on connect#297
datlechin merged 2 commits intomainfrom
fix/missing-plugin-connection-stuck

Conversation

@datlechin
Copy link
Copy Markdown
Collaborator

@datlechin datlechin commented Mar 12, 2026

Summary

  • DatabaseManager: Wrap DatabaseDriverFactory.createDriver() in a do/catch that cleans up the session (activeSessions, currentSessionId, SSH tunnel) when the plugin is missing. Previously the session stayed in .connecting status forever, leaving the main window stuck in a loading state.
  • ConnectionFormView: Add proper error handling in the generic catch branch — close the main window, reopen the welcome window, and show a "Connection Failed" alert. Previously it only logged the error silently.

Test plan

  • Create a connection for a database type whose plugin is not installed (e.g., Oracle, ClickHouse)
  • Click connect — verify the "Plugin Not Installed" prompt appears and main window does not stay stuck
  • For non-downloadable plugins, verify the "Connection Failed" alert appears and UI returns to welcome window
  • Verify normal connections (with plugins installed) still work correctly

Summary by CodeRabbit

  • Bug Fixes
    • Connection failures now show a "Connection Failed" error dialog and return the app to the welcome screen instead of only logging the error.
    • Improved cleanup when establishing a database connection fails, ensuring related resources and sessions are properly closed and cleared.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 12, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 7fd2c627-dd45-4024-93d3-3505e4b5ddd3

📥 Commits

Reviewing files that changed from the base of the PR and between 8cf68a6 and a2835c1.

📒 Files selected for processing (1)
  • TablePro/Views/Connection/ConnectionFormView.swift

📝 Walkthrough

Walkthrough

Adds defensive cleanup when database driver creation fails (SSH tunnel closed, session removed, currentSessionId cleared) and surfaces connection failures to the user by closing the main window, opening the welcome window, and presenting a "Connection Failed" error sheet.

Changes

Cohort / File(s) Summary
Database Driver Error Handling
TablePro/Core/Database/DatabaseManager.swift
On driver creation failure, closes any established SSH tunnel, removes the session, clears currentSessionId, and rethrows the error.
Connection Error UI Feedback
TablePro/Views/Connection/ConnectionFormView.swift
On connection failure (initial or post-plugin), closes main window, opens welcome window, and shows a "Connection Failed" error sheet with the error message.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 In burrows of code where connections may fray,
I tidy the tunnels and chase bugs away.
When drivers decline and errors take flight,
I hop to the welcome and show users the light.
Repaired, relaunched — now everything's right. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main changes: cleaning up session and UI when a driver plugin is missing on connect. It matches the PR objectives and file summaries.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/missing-plugin-connection-stuck
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
TablePro/Views/Connection/ConnectionFormView.swift (1)

1039-1046: Consider adding similar error handling here for consistency.

The connectAfterInstall method has the same connection flow but currently only logs errors. If connection fails after plugin installation, the main window could still get stuck in a loading state. Consider applying the same recovery pattern (close main, open welcome, show alert) for a consistent user experience.

This is not blocking for this PR, as it's outside the scope of the current fix.

♻️ Suggested improvement
     private func connectAfterInstall(_ connection: DatabaseConnection) {
         openWindow(id: "main", value: EditorTabPayload(connectionId: connection.id))
         NSApplication.shared.closeWindows(withId: "welcome")

         Task {
             do {
                 try await dbManager.connectToSession(connection)
             } catch {
                 Self.logger.error(
                     "Failed to connect after plugin install: \(error.localizedDescription, privacy: .public)")
+                NSApplication.shared.closeWindows(withId: "main")
+                openWindow(id: "welcome")
+                AlertHelper.showErrorSheet(
+                    title: String(localized: "Connection Failed"),
+                    message: error.localizedDescription,
+                    window: nil
+                )
             }
         }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@TablePro/Views/Connection/ConnectionFormView.swift` around lines 1039 - 1046,
The connectAfterInstall Task currently only logs errors; update its catch block
to perform the same recovery flow used elsewhere: after catching the error from
dbManager.connectToSession(connection) call inside connectAfterInstall, call the
existing closeMainWindow() and openWelcomeWindow() helpers (or their
equivalents) and then dispatch to the main actor to present the user-facing
alert (e.g., showAlert or presentInstallationFailureAlert) with the
error.localizedDescription; keep the Self.logger.error(...) call but append this
recovery sequence so the UI doesn't remain stuck loading when connection fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@TablePro/Views/Connection/ConnectionFormView.swift`:
- Around line 1039-1046: The connectAfterInstall Task currently only logs
errors; update its catch block to perform the same recovery flow used elsewhere:
after catching the error from dbManager.connectToSession(connection) call inside
connectAfterInstall, call the existing closeMainWindow() and openWelcomeWindow()
helpers (or their equivalents) and then dispatch to the main actor to present
the user-facing alert (e.g., showAlert or presentInstallationFailureAlert) with
the error.localizedDescription; keep the Self.logger.error(...) call but append
this recovery sequence so the UI doesn't remain stuck loading when connection
fails.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bd9360c6-ea62-4389-8a57-faadb4e7bdad

📥 Commits

Reviewing files that changed from the base of the PR and between 3db8b99 and 8cf68a6.

📒 Files selected for processing (2)
  • TablePro/Core/Database/DatabaseManager.swift
  • TablePro/Views/Connection/ConnectionFormView.swift

@datlechin datlechin merged commit 826b4d7 into main Mar 12, 2026
3 checks passed
@datlechin datlechin deleted the fix/missing-plugin-connection-stuck branch March 12, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant