<!--
{
  "availability" : [
    "iOS: 17.0.0 -",
    "iPadOS: 17.0.0 -",
    "macCatalyst: 17.0.0 -",
    "macOS: 14.0.0 -",
    "tvOS: 17.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 10.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftData",
  "identifier" : "/documentation/SwiftData/Query/fetchError",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "SwiftData",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:011_SwiftData_A2UI5QueryV10fetchErrors0F0_pSgvp"
  },
  "title" : "fetchError"
}
-->

# fetchError

An error encountered during the most recent attempt to fetch data.

```
@MainActor @preconcurrency var fetchError: (any Error)? { get }
```

## Discussion

This value is `nil` unless an fetch attempt failed. It contains the
latest error from SwiftData. Access it from Query’s stored property:

```
struct RecipeList: View {
    @Query var recipes: [Recipe]
    var body: some View {
        ErrorIndicatorView(_recipes.fetchError)
    }
}
```

> Note: Only access this property within of a view’s `body` property,
> otherwise its value may be invalid.

> Note: When an fetch error occurs, `wrappedValue` retains results from
> the last successful fetch. Its value will update once a new fetch
> succeeds.

---

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)