Skip to content

Add try-catch around localStorage operations #16

@Laurc2004

Description

@Laurc2004

Severity: LOW

Problem

src/routes/+page.svelte lines 165-169 and 181-183: localStorage.getItem() and localStorage.setItem() are guarded by typeof localStorage !== 'undefined' checks but lack try-catch for:

  • SecurityError: can occur in some Safari private browsing modes
  • QuotaExceededError: can occur if storage is full

A thrown exception would break the locale detection/save logic and potentially crash the component.

Proposed Solution

Wrap localStorage calls in try-catch:

function getLocale(): string {
  try {
    return localStorage.getItem(LOCALE_KEY) ?? DEFAULT_LOCALE;
  } catch {
    return DEFAULT_LOCALE;
  }
}

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions