Skip to content

feat(storage): Add error logging strategy for malformed localStorage data#165

Open
dreamgenies wants to merge 1 commit into
Tx-wat:mainfrom
dreamgenies:feat/68-storage-error-logging
Open

feat(storage): Add error logging strategy for malformed localStorage data#165
dreamgenies wants to merge 1 commit into
Tx-wat:mainfrom
dreamgenies:feat/68-storage-error-logging

Conversation

@dreamgenies
Copy link
Copy Markdown

Summary

Adds a lightweight, zero-dependency error logging layer for lib/storage.ts. Malformed localStorage data now emits a console.warn in development and fires registered hooks — enabling telemetry integration without crashing the app.

Changes

  • lib/storageLogger.ts:
    • safeParseStorage<T>(key, fallback): safe JSON.parse wrapper with fallback
    • onStorageError(handler): hook registration for telemetry / Sentry / tests
    • clearStorageErrorHandlers(): test utility
    • Dev logging via console.warn; suppressed in production unless DEBUG_STORAGE=true
  • lib/__tests__/storageLogger.test.ts: 6 tests covering all paths

Integration

Replace bare JSON.parse(localStorage.getItem(key)) calls in storage.ts with:

import { safeParseStorage } from './storageLogger';
const contracts = safeParseStorage<Contract[]>('txwatch:contracts', []);

Closes #68

…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
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@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! 🚀

Learn more about application limits

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.

Add storage error logging strategy

1 participant