Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ concurrency:
jobs:
swift_format:
name: swift-format
runs-on: macos-14
runs-on: macos-26
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Xcode Select
run: sudo xcode-select -s /Applications/Xcode_15.4.app
run: sudo xcode-select -s /Applications/Xcode_26.1.app
- name: Install
run: brew install swift-format
- name: Format
Expand Down
29 changes: 14 additions & 15 deletions Sources/IssueReporting/ErrorReporting.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// swift-format-ignore-file
// Note: Whitespace changes are used to workaround compiler bug
// https://github.com/swiftlang/swift/issues/79285

/// Evaluates a throwing closure and automatically catches and reports any error thrown.
///
/// - Parameters:
Expand All @@ -27,6 +23,7 @@ public func withErrorReporting<R>(
return withIssueReporters(reporters) {
do {
return try body()
} catch is CancellationError {
} catch {
reportIssue(
error,
Expand All @@ -36,12 +33,13 @@ public func withErrorReporting<R>(
line: line,
column: column
)
return nil
}
return nil
}
} else {
do {
return try body()
} catch is CancellationError {
} catch {
reportIssue(
error,
Expand All @@ -51,8 +49,8 @@ public func withErrorReporting<R>(
line: line,
column: column
)
return nil
}
return nil
}
}

Expand Down Expand Up @@ -110,13 +108,13 @@ public func withErrorReporting<R>(
line: UInt = #line,
column: UInt = #column,
isolation: isolated (any Actor)? = #isolation,
// DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
// https://github.com/swiftlang/swift/issues/79285
catching body: () async throws -> sending R) async -> R? {
catching body: () async throws -> sending R
) async -> R? {
if let reporters {
return await withIssueReporters(reporters) {
do {
return try await body()
} catch is CancellationError {
} catch {
reportIssue(
error,
Expand All @@ -126,12 +124,13 @@ public func withErrorReporting<R>(
line: line,
column: column
)
return nil
}
return nil
}
} else {
do {
return try await body()
} catch is CancellationError {
} catch {
reportIssue(
error,
Expand All @@ -141,8 +140,8 @@ public func withErrorReporting<R>(
line: line,
column: column
)
return nil
}
return nil
}
}

Expand All @@ -167,8 +166,6 @@ public func withErrorReporting<R>(
line: UInt = #line,
column: UInt = #column,
isolation: isolated (any Actor)? = #isolation,
// DO NOT FIX THE WHITESPACE IN THE NEXT LINE UNTIL 5.10 IS UNSUPPORTED
// https://github.com/swiftlang/swift/issues/79285
catching body: () async throws -> sending R?
) async -> R? {
(await withErrorReporting(
Expand Down Expand Up @@ -197,6 +194,7 @@ public func withErrorReporting<R>(
return await withIssueReporters(reporters) {
do {
return try await body()
} catch is CancellationError {
} catch {
reportIssue(
error,
Expand All @@ -206,12 +204,13 @@ public func withErrorReporting<R>(
line: line,
column: column
)
return nil
}
return nil
}
} else {
do {
return try await body()
} catch is CancellationError {
} catch {
reportIssue(
error,
Expand All @@ -221,8 +220,8 @@ public func withErrorReporting<R>(
line: line,
column: column
)
return nil
}
return nil
}
}

Expand Down
7 changes: 7 additions & 0 deletions Tests/IssueReportingTests/WithErrorReportingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@
}
}

@Test func cancellation() async {
await withErrorReporting {
await Task.yield()
throw CancellationError()
}
}

#if compiler(<6.2)
@MainActor
@Test func isolation() async {
Expand Down