Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions TablePro/Views/Connection/WelcomeWindowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -473,21 +473,26 @@ struct WelcomeWindowView: View {
do {
try await dbManager.connectToSession(connection)
} catch {
// Show error to user and re-open welcome window
await MainActor.run {
AlertHelper.showErrorSheet(
title: String(localized: "Connection Failed"),
message: error.localizedDescription,
window: nil
)
openWindow(id: "welcome")
}
Self.logger.error(
"Failed to connect: \(error.localizedDescription, privacy: .public)")
handleConnectionFailure(error: error)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Run failure recovery on the MainActor

In connectToDatabase, the catch path now calls handleConnectionFailure directly from an unstructured Task, but that helper performs AppKit/SwiftUI UI work (closeWindows, openWindow, AlertHelper.showErrorSheet). Because the previous await MainActor.run hop was removed, failed connections can execute UI operations off the main actor, which can trigger AppKit thread-safety crashes or undefined UI behavior during connection errors.

Useful? React with 👍 / 👎.

}
}
}

private func handleConnectionFailure(error: Error) {
// Close the main window first so macOS doesn't merge it with the welcome window
NSApplication.shared.closeWindows(withId: "main")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Close only the failed main window

handleConnectionFailure now calls NSApplication.shared.closeWindows(withId: "main"), and that helper closes all windows whose identifier contains main. In sessions where users already have other main windows open (for example after opening Welcome via “Manage Connections”), one failed connection attempt will close unrelated active windows/tabs and can drop in-progress work.

Useful? React with 👍 / 👎.

openWindow(id: "welcome")

// Show error as modal — welcome window is now the only window
AlertHelper.showErrorSheet(
title: String(localized: "Connection Failed"),
message: error.localizedDescription,
window: nil
)
}

private func deleteConnection(_ connection: DatabaseConnection) {
connections.removeAll { $0.id == connection.id }
storage.deleteConnection(connection)
Expand Down