Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling #40

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Error handling #40

wants to merge 19 commits into from

Conversation

stephencelis
Copy link
Member

@Shared persistence strategies can fail to load or save, but we have generally silently ignored such failures. This PR explores introducing loadError and saveError properties on the projected value, similar to SwiftData's @Query's fetchError.

@Shared(.fileStorage(.syncUps)) var syncUps: [SyncUp] = []

var body: some View {
  if let loadError = $syncUps.loadError {
    ContentUnavailableView {
      Label("Failed to load sync-ups", systemImage: "xmark.circle")
    } description: {
      Text(loadError.localizedDescription)
    }
  } else {
    ForEach(syncUps) { syncUp in
      // ...
    }
  }
}

@stephencelis stephencelis marked this pull request as ready for review December 11, 2024 22:41
@VilemKurz
Copy link

Hi, thank you for the pr, much needed and appreciated 👍. Wondering, will we be able to mock (pre-set) load/save errors in previews and tests?

@stephencelis
Copy link
Member Author

@VilemKurz As long as you mock the shared key's strategy to make it throw, then you should be able to test that $shared.loadError or $shared.saveError is populated.

Feel free to give this branch a spin and report back! Ideally we have some feedback from the community before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants