feat(storage): Add error logging strategy for malformed localStorage data#165
Open
dreamgenies wants to merge 1 commit into
Open
feat(storage): Add error logging strategy for malformed localStorage data#165dreamgenies wants to merge 1 commit into
dreamgenies wants to merge 1 commit into
Conversation
…hook (Tx-wat#68) - safeParseStorage<T>(): wraps JSON.parse, returns fallback + emits on failure - onStorageError(): consumer hook for telemetry / Sentry breadcrumbs - Logs to console.warn in dev; suppressed in production unless DEBUG_STORAGE=true - Handler errors never crash the app (try/catch around each handler) - Tests: valid parse, missing key, malformed JSON, hook fires, hook crash isolation Closes Tx-wat#68
|
@dreamgenies Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a lightweight, zero-dependency error logging layer for
lib/storage.ts. Malformed localStorage data now emits aconsole.warnin development and fires registered hooks — enabling telemetry integration without crashing the app.Changes
lib/storageLogger.ts:safeParseStorage<T>(key, fallback): safeJSON.parsewrapper with fallbackonStorageError(handler): hook registration for telemetry / Sentry / testsclearStorageErrorHandlers(): test utilityconsole.warn; suppressed in production unlessDEBUG_STORAGE=truelib/__tests__/storageLogger.test.ts: 6 tests covering all pathsIntegration
Replace bare
JSON.parse(localStorage.getItem(key))calls instorage.tswith:Closes #68