Skip to content

SwiftIdempotency 0.4.3 — property wrappers fail on a thrown error

Latest

Choose a tag to compare

@Joseph-Cursio Joseph-Cursio released this 24 Nov 20:13
· 2 commits to main since this release
a3ec7a5

SwiftIdempotency 0.4.3

Bug fix in the opt-in SwiftIdempotencyPropertyBased product. No API changes. One behaviour change: a property whose operation throws now fails.

Fixed

assertIdempotentProperty and assertIdempotentEffectsProperty passed when the operation threw

swift-property-based 1.0.0 through 2.0.1, on Swift 6.2 and later, runs a propertyCheck body under try?. An error that escapes the body is dropped, and the property passes (x-sheep/swift-property-based#29, open). Both wrappers called the operation, or apply, with a bare try. So a throwing operation passed silently. That included a store that refuses a duplicate on the retry, which is the bug a retry check exists to catch.

Both wrappers now catch inside the property and record the error as a failure. The message names the step that threw: the first call, the second call, the first pass, or the retry pass. Because the error is recorded inside the property, swift-property-based still counts it, shrinks it, and reports the input that failed. This holds on every swift-property-based release and on Swift before and after 6.2. It will not record twice once upstream fixes #29.

Two kinds of error are skipped, as Swift Testing itself skips them:

  • ExpectationFailedError: try #require has already recorded its own issue, so the failure is reported once.
  • Anything thrown after the task is cancelled (Test.cancel(), a .timeLimit expiry, an outer cancel): a cancelled test is not reported as a failure.

Migration

If a property that used to pass now fails with "the operation threw during …", the operation really is throwing on a generated input. Two cases:

  • The throw is a bug. The wrapper is now doing its job.
  • The handler throws on a duplicate by design (check-then-throw dedup). Catch that error inside the closure, and test the throwing return contract separately. This is the same recipe as the non-property helpers; see USER_GUIDE, "Throw-on-retry handlers".

Validation

  • ThrownErrorTests (8 cases) covers both wrappers. Each case fails when the part it guards is removed: the catch, the ExpectationFailedError guard, the cancellation guard.
  • Full suite green on Swift 6.4.1 (swift.org toolchain); swiftlint --strict clean.
  • The two wrapper mutants are regenerated for the new code, and mutants/run-mutants.sh still kills both.

Full change: #25