AOSSIE-Org / AOSSIE-Org/DebateAI

[BUG] App crashes due to unsafe access on null values from storage

Đang mở
#145 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
84
Fork
198
Merge trung bình
2 ngày 19 giờ
Pull request đã merge (30 ngày)
30

Mô tả

## Description:

The application crashes at runtime with the following error:
TypeError: Cannot read properties of null (reading 'length')
This occurs when the app attempts to access .length on a value retrieved from localStorage (or similar storage) that is null.
This commonly happens for new users / fresh sessions where expected keys are not yet present in storage.

## Steps to Reproduce

Open the app in a fresh browser session (clear localStorage / incognito).
Navigate through the app until storage cleanup or quote-related logic runs.

The app crashes with:

Cannot read properties of null (reading 'length')

## Expected Behavior

The app should safely handle missing or unset storage values and not crash.

## Actual Behavior

The app crashes because .length is accessed on a null value.

## Root Cause (Analysis)

Code assumes values from storage are always non-null, for example:

const value = localStorage.getItem(key);
if (value.length > 0) { ... } // crashes if value === null

However, localStorage.getItem() returns null if the key does not exist.

## Suggested Fix

Add defensive checks or defaults before accessing .length, for example:

const value = localStorage.getItem(key);
if (!value) return;
if (value.length > 0) {
...
}

or:

const value = JSON.parse(localStorage.getItem(key) ?? "[]");

## Impact

🚨 Causes hard crashes
🚨 Affects new users
🚨 Breaks core functionality
🚨 Generates excessive error reports (Sentry)

## Environment

Frontend: React + Vite

Browser: Any

Reproducible: Yes (100% on fresh storage)

## Additional Notes

This issue can be resolved by adding simple null guards and/or safe parsing when accessing storage values.

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.