---
title: fetchError
framework: swiftdata
role: symbol
role_heading: Instance Property
path: swiftdata/query/fetcherror
---

# fetchError

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

## Declaration

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

## Discussion

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.

## See Also

### Getting query configuration

- [modelContext](swiftdata/query/modelcontext.md)
