Skip to content

Commit cfa7323

Browse files
committed
Present errors in widget
1 parent a66bbe7 commit cfa7323

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

Core/Sources/Service/SuggestionCommandHandler/WindowBaseCommandHandler.swift

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
1717
do {
1818
try await _presentSuggestions(editor: editor)
1919
} catch {
20+
presenter.presentError(error)
2021
Logger.service.error(error)
2122
}
2223
}
@@ -63,7 +64,11 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
6364

6465
func presentNextSuggestion(editor: EditorContent) async throws -> UpdatedContent? {
6566
Task {
66-
try await _presentNextSuggestion(editor: editor)
67+
do {
68+
try await _presentNextSuggestion(editor: editor)
69+
} catch {
70+
presenter.presentError(error)
71+
}
6772
}
6873
return nil
6974
}
@@ -92,7 +97,11 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
9297

9398
func presentPreviousSuggestion(editor: EditorContent) async throws -> UpdatedContent? {
9499
Task {
95-
try await _presentPreviousSuggestion(editor: editor)
100+
do {
101+
try await _presentPreviousSuggestion(editor: editor)
102+
} catch {
103+
presenter.presentError(error)
104+
}
96105
}
97106
return nil
98107
}
@@ -121,7 +130,11 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
121130

122131
func rejectSuggestion(editor: EditorContent) async throws -> UpdatedContent? {
123132
Task {
124-
try await _rejectSuggestion(editor: editor)
133+
do {
134+
try await _rejectSuggestion(editor: editor)
135+
} catch {
136+
presenter.presentError(error)
137+
}
125138
}
126139
return nil
127140
}
@@ -147,6 +160,7 @@ struct WindowBaseCommandHandler: SuggestionCommandHandler {
147160
}
148161
return result
149162
} catch {
163+
presenter.presentError(error)
150164
throw error
151165
}
152166
}

Core/Sources/Service/SuggestionPresenter/PresentInWindowSuggestionPresenter.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,11 @@ struct PresentInWindowSuggestionPresenter {
3636
controller.markAsProcessing(isProcessing)
3737
}
3838
}
39+
40+
func presentError(_ error: Error) {
41+
Task { @MainActor in
42+
let controller = GraphicalUserInterfaceController.shared.suggestionWidget
43+
controller.presentError(error.localizedDescription)
44+
}
45+
}
3946
}

Core/Sources/SuggestionWidget/SuggestionPanelContent/ErrorPanel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ struct ErrorPanel: View {
2121
Image(systemName: "xmark")
2222
.padding([.leading, .bottom], 16)
2323
.padding([.top, .trailing], 8)
24+
.foregroundColor(.white)
2425
}
2526
.buttonStyle(.plain)
2627
}

Core/Sources/SuggestionWidget/SuggestionWidgetController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@ public extension SuggestionWidgetController {
237237

238238
func presentError(_ errorDescription: String) {
239239
suggestionPanelViewModel.content = .error(errorDescription)
240+
widgetViewModel.isProcessing = false
241+
suggestionPanelViewModel.isPanelDisplayed = true
240242
}
241243
}
242244

0 commit comments

Comments
 (0)