Skip to content

Commit 835e19e

Browse files
committed
wip
1 parent f5b7c76 commit 835e19e

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# ``IssueReporting/withErrorReporting(_:fileID:filePath:line:column:catching:)-3k8o``
1+
# ``IssueReporting/withErrorReporting(_:to:fileID:filePath:line:column:catching:)-89omf``
22

33
## Topics
44

55
### Overloads
66

7-
- ``withErrorReporting(_:fileID:filePath:line:column:catching:)-r4f1``
7+
- ``withErrorReporting(_:to:fileID:filePath:line:column:catching:)-3dh1h``

Sources/IssueReporting/Documentation.docc/IssueReporting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ that ship in the same target as the library itself.
5353

5454
- ``reportIssue(_:fileID:filePath:line:column:)``
5555
- ``withExpectedIssue(_:isIntermittent:fileID:filePath:line:column:_:)-9pinm``
56-
- ``withErrorReporting(_:fileID:filePath:line:column:catching:)-3k8o``
56+
- ``withErrorReporting(_:to:fileID:filePath:line:column:catching:)-89omf``
5757

5858
### Issue reporters
5959

Sources/IssueReporting/ErrorReporting.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/// Evaluates a throwing closure and automatically catches and reports any error thrown.
22
///
33
/// - Parameters:
4+
/// - message: A message describing the expectation.
45
/// - reporters: Issue reporters to notify during the operation.
56
/// - fileID: The source `#fileID` associated with the error reporting.
67
/// - filePath: The source `#filePath` associated with the error reporting.
@@ -10,7 +11,8 @@
1011
/// - Returns: The optional result of the operation, or `nil` if an error was thrown.
1112
@_transparent
1213
public func withErrorReporting<R>(
13-
_ reporters: [any IssueReporter]? = nil,
14+
_ message: @autoclosure () -> String? = nil,
15+
to reporters: [any IssueReporter]? = nil,
1416
fileID: StaticString = #fileID,
1517
filePath: StaticString = #filePath,
1618
line: UInt = #line,
@@ -22,15 +24,29 @@ public func withErrorReporting<R>(
2224
do {
2325
return try body()
2426
} catch {
25-
reportIssue(error, fileID: fileID, filePath: filePath, line: line, column: column)
27+
reportIssue(
28+
error,
29+
message(),
30+
fileID: fileID,
31+
filePath: filePath,
32+
line: line,
33+
column: column
34+
)
2635
return nil
2736
}
2837
}
2938
} else {
3039
do {
3140
return try body()
3241
} catch {
33-
reportIssue(error, fileID: fileID, filePath: filePath, line: line, column: column)
42+
reportIssue(
43+
error,
44+
message(),
45+
fileID: fileID,
46+
filePath: filePath,
47+
line: line,
48+
column: column
49+
)
3450
return nil
3551
}
3652
}
@@ -39,6 +55,7 @@ public func withErrorReporting<R>(
3955
/// Evaluates a throwing closure and automatically catches and reports any error thrown.
4056
///
4157
/// - Parameters:
58+
/// - message: A message describing the expectation.
4259
/// - reporters: Issue reporters to notify during the operation.
4360
/// - fileID: The source `#fileID` associated with the error reporting.
4461
/// - filePath: The source `#filePath` associated with the error reporting.
@@ -48,7 +65,8 @@ public func withErrorReporting<R>(
4865
/// - Returns: The optional result of the operation, or `nil` if an error was thrown.
4966
@_transparent
5067
public func withErrorReporting<R>(
51-
_ reporters: [any IssueReporter]? = nil,
68+
_ message: @autoclosure () -> String? = nil,
69+
to reporters: [any IssueReporter]? = nil,
5270
fileID: StaticString = #fileID,
5371
filePath: StaticString = #filePath,
5472
line: UInt = #line,

Tests/IssueReportingTests/WithErrorReportingTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
} matching: { issue in
1313
issue.description == "Caught error: SomeError()"
1414
}
15+
16+
withKnownIssue {
17+
withErrorReporting("Failed") {
18+
throw SomeError()
19+
}
20+
} matching: { issue in
21+
issue.description == "Caught error: SomeError(): Failed"
22+
}
1523
}
1624
}
1725

0 commit comments

Comments
 (0)