Skip to content

Improve error logging in theme toggle #29

@ahmed-abdat

Description

@ahmed-abdat

Currently, errors in localStorage operations fail silently, making debugging difficult.

Task

Add console.warn() to catch blocks for better debugging.

Location

js/theme-toggle.js - Lines 17 and 27

Current Code (Silent)

try {
  localStorage.setItem("theme", theme);
} catch (e) {}  // ❌ Silent - errors disappear

Improved Code

try {
  localStorage.setItem("theme", theme);
} catch (e) {
  console.warn("Unable to save theme preference:", e);
}

Files to Update

  • Line 17: localStorage.getItem catch
  • Line 27: localStorage.setItem catch

Testing

  1. Test in private browsing (localStorage disabled)
  2. Check console for warnings
  3. Theme should still work (graceful degradation)

Learning Opportunity

Learn about:

  • Error handling best practices
  • Console logging
  • Graceful degradation

Difficulty: Easy
Estimated Time: 10-15 minutes
Related: PR #26

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions