-
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Issue Description
The window.onload handler is async and calls init(), but doesn't have proper error handling. If retrievePageData() or retrieveArticleData() fail, the page initialization stops silently without user feedback.
Risk Level
MEDIUM
Affected Files
src/scripts/index.js(Lines 576-580)
Details
Current Code
window.onload = async function () {
await registerServiceWorker();
init(); // No try-catch here!
};Where init() calls:
function init() {
ArticleFiller.retrievePageData();
ArticleFiller.retrieveArticleData();
}Problems
- If
retrievePageData()orretrieveArticleData()throw errors, they're not caught - Page appears to be loading but nothing happens
- Users have no visual feedback that something went wrong
- No error recovery mechanism
Example Failure Scenario
- Network is slow or unreachable
- articleData.json returns 404
- User sees blank page with no error message
Expected Behavior
- All fetch operations should be wrapped in try-catch
- User should see an error message if data cannot be loaded
- Fallback behavior (e.g., show header, suggest refresh) should be available
Solution Approach
-
Wrap
init()call in try-catch:window.onload = async function () { try { await registerServiceWorker(); init(); } catch (error) { console.error('Page initialization failed:', error); ArticleFiller.displayError('Failed to load page. Please refresh or try again later.'); } };
-
Ensure
retrievePageData()andretrieveArticleData()have proper error handlers -
Add timeout protection to prevent indefinite loading states
Labels
quality, error-handling, resilience
Reactions are currently unavailable