Skip to content

Commit 124facf

Browse files
committed
Testing/Polling Confirmations: Add a failure reason API
1 parent f6c57d5 commit 124facf

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

proposals/testing/NNNN-polling-confirmations.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,37 @@ public enum PollingStopCondition: Sendable, Equatable {
256256
}
257257
```
258258

259+
### New `PollingFailureReason` enum
260+
261+
There are 2 reasons why polling confirmations can fail: the stop condition
262+
failed, or the confirmation was cancelled during the run. To help express this,
263+
we will be adding a new `PollingFailureReason` enum.
264+
265+
```swift
266+
/// A type describing why polling failed
267+
public enum PollingFailureReason: Sendable, Codable {
268+
/// The polling failed because it was cancelled using `Task.cancel`.
269+
case cancelled
270+
271+
/// The polling failed because the stop condition failed.
272+
case stopConditionFailed(PollingStopCondition)
273+
}
274+
```
275+
259276
### New Error Type
260277

261278
A new error type, `PollingFailedError` to be thrown when the polling
262279
confirmation doesn't pass:
263280

264281
```swift
265282
/// A type describing an error thrown when polling fails.
266-
public struct PollingFailedError: Error, Sendable {}
283+
public struct PollingFailedError: Error, Sendable {
284+
/// A user-specified comment describing this confirmation
285+
public var comment: Comment? { get }
286+
287+
/// Why polling failed, either cancelled, or because the stop condition failed.
288+
public var reason: PollingFailureReason { get }
289+
}
267290
```
268291

269292
### New `Issue.Kind` case
@@ -279,11 +302,15 @@ public struct Issue {
279302

280303
/// An issue due to a polling confirmation having failed.
281304
///
305+
/// - Parameters:
306+
/// - reason: The ``PollingFailureReason`` behind why the polling
307+
/// confirmation failed.
308+
///
282309
/// This issue can occur when calling ``confirmation(_:until:within:pollingEvery:isolation:sourceLocation:_:)-455gr``
283310
/// or
284311
/// ``confirmation(_:until:within:pollingEvery:isolation:sourceLocation:_:)-5tnlk``
285312
/// whenever the polling fails, as described in ``PollingStopCondition``.
286-
case pollingConfirmationFailed
313+
case pollingConfirmationFailed(reason: PollingFailureReason)
287314

288315
// ...
289316
}

0 commit comments

Comments
 (0)