<!--
{
  "availability" : [
    "Xcode: 16.0.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/withKnownIssue(_:isIntermittent:isolation:sourceLocation:_:when:matching:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Swift Testing"
    ],
    "preciseIdentifier" : "s:7Testing14withKnownIssue_14isIntermittent9isolation14sourceLocation_4when8matchingyAA7CommentVSg_SbScA_pSgYiAA06SourceI0VyyYaKXESbyYaXESbAA0D0VYbctYaKF"
  },
  "title" : "withKnownIssue(_:isIntermittent:isolation:sourceLocation:_:when:matching:)"
}
-->

# withKnownIssue(_:isIntermittent:isolation:sourceLocation:_:when:matching:)

Invoke a function that has a known issue that is expected to occur during
its execution.

```
func withKnownIssue(_ comment: Comment? = nil, isIntermittent: Bool = false, isolation: isolated (any Actor)? = #isolation, sourceLocation: SourceLocation = #_sourceLocation, _ body: () async throws -> Void, when precondition: () async -> Bool = { true }, matching issueMatcher: @escaping KnownIssueMatcher = { _ in true }) async rethrows
```

## Parameters

`comment`

An optional comment describing the known issue.

`isIntermittent`

Whether or not the known issue occurs intermittently. If
this argument is `true` and the known issue does not occur, no secondary
issue is recorded.

`isolation`

The actor to which `body` is isolated, if any.

`sourceLocation`

The source location to which any recorded issues should
be attributed.

`body`

The function to invoke.

`precondition`

A function that determines if issues are known to occur
during the execution of `body`. If this function returns `true`,
encountered issues that are matched by `issueMatcher` are considered to
be known issues; if this function returns `false`, `issueMatcher` is not
called and they are treated as unknown.

`issueMatcher`

A function to invoke when an issue occurs that is used to
determine if the issue is known to occur. By default, all issues match.

## Discussion> Throws: Whatever is thrown by `body`, unless it is matched by
> `issueMatcher`.

Use this function when a test is known to record one or more issues that
should not cause the test to fail, or if a precondition affects whether
issues are known to occur. For example:

```swift
@Test func example() async throws {
  try await withKnownIssue {
    try await flakyCall()
  } when: {
    callsAreFlakyOnThisPlatform()
  } matching: { issue in
    issue.error is FileNotFoundError
  }
}
```

It is not necessary to specify both `precondition` and `issueMatcher` if
only one is relevant. If all errors and issues should be considered known
issues, use [`withKnownIssue(_:isIntermittent:isolation:sourceLocation:_:when:matching:)`](/documentation/Testing/withKnownIssue(_:isIntermittent:isolation:sourceLocation:_:when:matching:))
instead.

> Note: `issueMatcher` may be invoked more than once for the same issue.

## See Also

[Known issues](/documentation/Testing/known-issues)

Mark issues as known when running tests.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)