1- // swift-format-ignore-file
2- // Note: Whitespace changes are used to workaround compiler bug
3- // https://github.com/swiftlang/swift/issues/79285
4-
51/// Evaluates a throwing closure and automatically catches and reports any error thrown.
62///
73/// - Parameters:
@@ -27,6 +23,7 @@ public func withErrorReporting<R>(
2723 return withIssueReporters ( reporters) {
2824 do {
2925 return try body ( )
26+ } catch is CancellationError {
3027 } catch {
3128 reportIssue (
3229 error,
@@ -36,12 +33,13 @@ public func withErrorReporting<R>(
3633 line: line,
3734 column: column
3835 )
39- return nil
4036 }
37+ return nil
4138 }
4239 } else {
4340 do {
4441 return try body ( )
42+ } catch is CancellationError {
4543 } catch {
4644 reportIssue (
4745 error,
@@ -51,8 +49,8 @@ public func withErrorReporting<R>(
5149 line: line,
5250 column: column
5351 )
54- return nil
5552 }
53+ return nil
5654 }
5755}
5856
@@ -110,13 +108,13 @@ public func withErrorReporting<R>(
110108 line: UInt = #line,
111109 column: UInt = #column,
112110 isolation: isolated ( any Actor ) ? = #isolation,
113- // DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
114- // https://github.com/swiftlang/swift/issues/79285
115- catching body: ( ) async throws -> sending R) async -> R ? {
111+ catching body: ( ) async throws -> sending R
112+ ) async -> R ? {
116113 if let reporters {
117114 return await withIssueReporters ( reporters) {
118115 do {
119116 return try await body ( )
117+ } catch is CancellationError {
120118 } catch {
121119 reportIssue (
122120 error,
@@ -126,12 +124,13 @@ public func withErrorReporting<R>(
126124 line: line,
127125 column: column
128126 )
129- return nil
130127 }
128+ return nil
131129 }
132130 } else {
133131 do {
134132 return try await body ( )
133+ } catch is CancellationError {
135134 } catch {
136135 reportIssue (
137136 error,
@@ -141,8 +140,8 @@ public func withErrorReporting<R>(
141140 line: line,
142141 column: column
143142 )
144- return nil
145143 }
144+ return nil
146145 }
147146 }
148147
@@ -167,8 +166,6 @@ public func withErrorReporting<R>(
167166 line: UInt = #line,
168167 column: UInt = #column,
169168 isolation: isolated ( any Actor ) ? = #isolation,
170- // DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
171- // https://github.com/swiftlang/swift/issues/79285
172169 catching body: ( ) async throws -> sending R?
173170 ) async -> R ? {
174171 ( await withErrorReporting (
@@ -197,6 +194,7 @@ public func withErrorReporting<R>(
197194 return await withIssueReporters ( reporters) {
198195 do {
199196 return try await body ( )
197+ } catch is CancellationError {
200198 } catch {
201199 reportIssue (
202200 error,
@@ -206,12 +204,13 @@ public func withErrorReporting<R>(
206204 line: line,
207205 column: column
208206 )
209- return nil
210207 }
208+ return nil
211209 }
212210 } else {
213211 do {
214212 return try await body ( )
213+ } catch is CancellationError {
215214 } catch {
216215 reportIssue (
217216 error,
@@ -221,8 +220,8 @@ public func withErrorReporting<R>(
221220 line: line,
222221 column: column
223222 )
224- return nil
225223 }
224+ return nil
226225 }
227226 }
228227
0 commit comments