Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions code/experiment.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,9 +473,11 @@ async function executeBatchPayload() {
setTimeout(onSyncSuccess, 1500); // Simulate sync delay
}
} catch (error) {
console.error("Critical Sync Failure:", error);
DOM.syncStatus.innerHTML = `<span style="color:#ff453a">⚠️ Sync Failed. Error: ${error.code || 'Network'}</span>`;
// Potential fallback: Save to localStorage for later recovery
// Fallback: Save to localStorage for later recovery
localStorage.setItem(`telemetry_backup_${STATE.pid}`, JSON.stringify(STATE.results));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The localStorage.setItem call can throw an exception if storage is full or disabled (e.g., in private browsing mode). This would interrupt the catch block and prevent the user from seeing the final status message. To make the error handling more robust, this operation should be wrapped in its own try...catch block to ensure the UI is always updated, even if the data backup fails.

        try {
            localStorage.setItem(`telemetry_backup_${STATE.pid}`, JSON.stringify(STATE.results));
        } catch (storageError) {
            // Silently fail if localStorage is not available to ensure the UI message is shown.
        }

Comment on lines +476 to +477

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback persists a new telemetry_backup_${STATE.pid} entry but there’s no cleanup or indexing; repeated failures can accumulate orphaned payloads in localStorage and eventually cause quota issues, and recovery is harder because the PID isn’t surfaced when sync fails. Consider adding a bounded retention strategy (e.g., store an index/timestamp, cap number of backups) and removing the backup once a later sync succeeds.

Copilot uses AI. Check for mistakes.

DOM.syncStatus.style.color = "#ff453a";
DOM.syncStatus.textContent = "Diagnostic Complete. A network timeout occurred. You may safely close this tab.";
Comment on lines +479 to +480

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The color string #ff453a and the UI message are hardcoded. To improve maintainability and avoid "magic values," consider defining these as constants at a higher scope (e.g., in the CFG object at the top of the file). This makes them easier to find, update, and ensures consistency if they are used elsewhere.

Comment on lines +476 to +480

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

localStorage.setItem(...) can throw (e.g., QuotaExceededError, storage disabled/private mode). Since this is inside the catch, a thrown storage error would escape and prevent the user-facing status update, defeating the fallback. Wrap the localStorage write in its own try/catch and ensure the UI message is still shown even if persistence fails (optionally showing a different message when storage is unavailable).

Suggested change
// Fallback: Save to localStorage for later recovery
localStorage.setItem(`telemetry_backup_${STATE.pid}`, JSON.stringify(STATE.results));
DOM.syncStatus.style.color = "#ff453a";
DOM.syncStatus.textContent = "Diagnostic Complete. A network timeout occurred. You may safely close this tab.";
// Fallback: Attempt to save to localStorage for later recovery
let message = "Diagnostic Complete. A network timeout occurred. You may safely close this tab.";
try {
localStorage.setItem(`telemetry_backup_${STATE.pid}`, JSON.stringify(STATE.results));
} catch (storageError) {
console.warn("Unable to persist telemetry backup to localStorage:", storageError);
message = "Diagnostic Complete. A network timeout occurred and local backup could not be saved. You may safely close this tab.";
}
DOM.syncStatus.style.color = "#ff453a";
DOM.syncStatus.textContent = message;

Copilot uses AI. Check for mistakes.
}
}

Expand Down
Loading