Skip to content

Commit 27694b5

Browse files
authored
flush observability on error (#5595)
motivation: follow up on previsou changes to queue observability messages changes: catch error an flush on those cases as well
1 parent 3799095 commit 27694b5

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Sources/Commands/SwiftTool.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,21 @@ protocol SwiftCommand: ParsableCommand {
209209
extension SwiftCommand {
210210
public func run() throws {
211211
let swiftTool = try SwiftTool(options: globalOptions)
212-
try self.run(swiftTool)
213-
swiftTool.waitForObservabilityEvents(timeout: .now() + 5) // wait for all observability items to process
214-
if swiftTool.observabilityScope.errorsReported || swiftTool.executionStatus == .failure {
215-
throw ExitCode.failure
212+
var toolError: Error? = .none
213+
do {
214+
try self.run(swiftTool)
215+
if swiftTool.observabilityScope.errorsReported || swiftTool.executionStatus == .failure {
216+
throw ExitCode.failure
217+
}
218+
} catch {
219+
toolError = error
220+
}
221+
222+
// wait for all observability items to process
223+
swiftTool.waitForObservabilityEvents(timeout: .now() + 5)
224+
225+
if let error = toolError {
226+
throw error
216227
}
217228
}
218229

0 commit comments

Comments
 (0)