Skip to content

fix: add error logging to AsyncStorage catch blocks - #3866

Open
gugli4ifenix-design wants to merge 3 commits into
urql-graphql:mainfrom
gugli4ifenix-design:fix/async-storage-error-logging
Open

fix: add error logging to AsyncStorage catch blocks#3866
gugli4ifenix-design wants to merge 3 commits into
urql-graphql:mainfrom
gugli4ifenix-design:fix/async-storage-error-logging

Conversation

@gugli4ifenix-design

Copy link
Copy Markdown

Problem

makeAsyncStorage.ts has 8 empty catch blocks that silently swallow all AsyncStorage errors:

try {
  persistedData = await AsyncStorage.getItem(dataKey);
} catch (_err) {} // all errors silently lost

If AsyncStorage fails (permissions, full disk, corrupted data), persisted data is silently lost with no indication to the developer.

Fix

Add console.warn guarded by __DEV__ — errors are logged during development, production behavior unchanged:

} catch (_err) {
  if (__DEV__) console.warn("[urql] AsyncStorage error:", _err);
}
  • 8 catch blocks updated in packages/storage-rn/src/makeAsyncStorage.ts
  • Production safe — no logging in release builds
  • Behavior unchanged — still fails silently, but developers can now see why

Found during a static analysis sweep of 97 popular open source projects.

8 empty catch blocks in makeAsyncStorage.ts silently swallow all
AsyncStorage errors. If storage fails (permissions, full disk,
corrupted data), the app silently loses persisted data with no
indication to the developer.

This adds console.warn in __DEV__ mode, preserving the existing
fail-silently behavior in production while making storage issues
visible during development.

Found during a static analysis sweep of 97 popular open source projects.
@changeset-bot

changeset-bot Bot commented Apr 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: e112f68

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@kitten

kitten commented Jun 14, 2026

Copy link
Copy Markdown
Member

I think this should at least have an onError option, as the examples you gave are valid, but would likely require developer intervention in shipped apps to inform users or to have a way to recover from these errors.

Let me know if you're still interested in picking this up, otherwise happy to push a patch to this branch to get this shipped

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