@@ -52,42 +52,104 @@ public func withErrorReporting<R>(
5252 }
5353}
5454
55- /// Evaluates a throwing closure and automatically catches and reports any error thrown.
56- ///
57- /// - Parameters:
58- /// - message: A message describing the expectation.
59- /// - reporters: Issue reporters to notify during the operation.
60- /// - fileID: The source `#fileID` associated with the error reporting.
61- /// - filePath: The source `#filePath` associated with the error reporting.
62- /// - line: The source `#line` associated with the error reporting.
63- /// - column: The source `#column` associated with the error reporting.
64- /// - body: An asynchronous operation.
65- /// - Returns: The optional result of the operation, or `nil` if an error was thrown.
66- @_transparent
67- public func withErrorReporting< R> (
68- _ message: @autoclosure ( ) -> String ? = nil ,
69- to reporters: [ any IssueReporter ] ? = nil ,
70- fileID: StaticString = #fileID,
71- filePath: StaticString = #filePath,
72- line: UInt = #line,
73- column: UInt = #column,
74- catching body: ( ) async throws -> R
75- ) async -> R ? {
76- if let reporters {
77- return await withIssueReporters ( reporters) {
55+ #if compiler(>=6)
56+ /// Evaluates a throwing closure and automatically catches and reports any error thrown.
57+ ///
58+ /// - Parameters:
59+ /// - message: A message describing the expectation.
60+ /// - reporters: Issue reporters to notify during the operation.
61+ /// - fileID: The source `#fileID` associated with the error reporting.
62+ /// - filePath: The source `#filePath` associated with the error reporting.
63+ /// - line: The source `#line` associated with the error reporting.
64+ /// - column: The source `#column` associated with the error reporting.
65+ /// - isolation: The isolation associated with the error reporting.
66+ /// - body: An asynchronous operation.
67+ /// - Returns: The optional result of the operation, or `nil` if an error was thrown.
68+ @_transparent
69+ public func withErrorReporting< R> (
70+ _ message: @autoclosure ( ) -> String ? = nil ,
71+ to reporters: [ any IssueReporter ] ? = nil ,
72+ fileID: StaticString = #fileID,
73+ filePath: StaticString = #filePath,
74+ line: UInt = #line,
75+ column: UInt = #column,
76+ isolation: isolated ( any Actor ) ? = #isolation,
77+ catching body: ( ) async throws -> sending R
78+ ) async -> R ? {
79+ if let reporters {
80+ return await withIssueReporters ( reporters) {
81+ do {
82+ return try await body ( )
83+ } catch {
84+ reportIssue (
85+ error,
86+ message ( ) ,
87+ fileID: fileID,
88+ filePath: filePath,
89+ line: line,
90+ column: column
91+ )
92+ return nil
93+ }
94+ }
95+ } else {
7896 do {
7997 return try await body ( )
8098 } catch {
81- reportIssue ( error, fileID: fileID, filePath: filePath, line: line, column: column)
99+ reportIssue (
100+ error,
101+ message ( ) ,
102+ fileID: fileID,
103+ filePath: filePath,
104+ line: line,
105+ column: column
106+ )
82107 return nil
83108 }
84109 }
85- } else {
86- do {
87- return try await body ( )
88- } catch {
89- reportIssue ( error, fileID: fileID, filePath: filePath, line: line, column: column)
90- return nil
110+ }
111+ #else
112+ @_transparent
113+ @_unsafeInheritExecutor
114+ public func withErrorReporting< R> (
115+ _ message: @autoclosure ( ) -> String ? = nil ,
116+ to reporters: [ any IssueReporter ] ? = nil ,
117+ fileID: StaticString = #fileID,
118+ filePath: StaticString = #filePath,
119+ line: UInt = #line,
120+ column: UInt = #column,
121+ catching body: ( ) async throws -> R
122+ ) async -> R ? {
123+ if let reporters {
124+ return await withIssueReporters ( reporters) {
125+ do {
126+ return try await body ( )
127+ } catch {
128+ reportIssue (
129+ error,
130+ message ( ) ,
131+ fileID: fileID,
132+ filePath: filePath,
133+ line: line,
134+ column: column
135+ )
136+ return nil
137+ }
138+ }
139+ } else {
140+ do {
141+ return try await body ( )
142+ } catch {
143+ reportIssue (
144+ error,
145+ message ( ) ,
146+ fileID: fileID,
147+ filePath: filePath,
148+ line: line,
149+ column: column
150+ )
151+ return nil
152+ }
91153 }
92154 }
93- }
155+ #endif
0 commit comments