refactor: selective catches in Chrome extension files

Convert empty catches and error-swallowing patterns across inspector.js,
content.js, background.js, and sidepanel.js. DOM catches filter
TypeError/DOMException, chrome API catches filter Extension context
invalidated, network catches filter Failed to fetch. Unexpected errors
now propagate.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Garry Tan
2026-04-09 04:54:32 -10:00
parent b8c4e703c6
commit 5f9246ac23
4 changed files with 37 additions and 22 deletions

View File

@@ -46,7 +46,8 @@ async function loadAuthToken() {
if (data.token) authToken = data.token;
}
} catch (err) {
console.error('[gstack bg] Failed to load auth token:', err.message);
if (!err?.message?.includes('Failed to fetch')) throw err;
console.debug('[gstack bg] Auth token not available (server may not be running):', err.message);
}
}
@@ -125,7 +126,8 @@ async function notifyContentScripts(type) {
}
}
} catch (err) {
console.error('[gstack bg] Failed to query tabs for notification:', err.message);
if (!err?.message?.includes('Extension context invalidated')) throw err;
console.debug('[gstack bg] Tab notification skipped (extension context invalidated)');
}
}
@@ -180,7 +182,8 @@ async function fetchAndRelayRefs() {
}
}
} catch (err) {
console.error('[gstack bg] Failed to fetch/relay refs:', err.message);
if (!err?.message?.includes('Failed to fetch')) throw err;
console.debug('[gstack bg] Refs fetch skipped (server unreachable)');
}
}
@@ -203,13 +206,15 @@ async function injectInspector(tabId) {
files: ['inspector.css'],
});
} catch (err) {
if (!err?.message?.includes('Extension context invalidated') && !err?.message?.includes('Cannot access')) throw err;
console.debug('[gstack bg] Inspector CSS injection failed (non-fatal):', err.message);
}
// Send startPicker to the injected inspector.js
try {
await chrome.tabs.sendMessage(tabId, { type: 'startPicker' });
} catch (err) {
console.warn('[gstack bg] Failed to send startPicker:', err.message);
if (!err?.message?.includes('Extension context invalidated') && !err?.message?.includes('Receiving end does not exist')) throw err;
console.debug('[gstack bg] startPicker skipped (tab not ready):', err.message);
}
inspectorMode = 'full';
return { ok: true, mode: 'full' };
@@ -232,7 +237,8 @@ async function stopInspector(tabId) {
try {
await chrome.tabs.sendMessage(tabId, { type: 'stopPicker' });
} catch (err) {
console.debug('[gstack bg] Failed to stop picker on tab', tabId, ':', err.message);
if (!err?.message?.includes('Extension context invalidated') && !err?.message?.includes('Receiving end does not exist')) throw err;
console.debug('[gstack bg] stopPicker skipped (tab not ready):', err.message);
}
return { ok: true };
}
@@ -270,7 +276,8 @@ async function sendToContentScript(tabId, message) {
try {
const response = await chrome.tabs.sendMessage(tabId, message);
return response || { ok: true };
} catch {
} catch (e) {
if (!e?.message?.includes('Extension context invalidated') && !e?.message?.includes('Receiving end does not exist')) throw e;
return { error: 'Content script not available' };
}
}