mirror of https://github.com/garrytan/gstack.git
fix(browse): surface auto-cookie state read errors instead of swallowing
loadAutoCookieState treated every read failure as the benign corrupt-file case and returned null silently. Split the file read from the JSON parse: a read error (e.g. EACCES) now logs a warning — the device cookie won't restore and that should be visible — while a JSON parse failure stays silent (a later save overwrites it). Addresses a slop-scan default-return/filesystem finding. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
2f2ed32b46
commit
1404106293
|
|
@ -258,12 +258,21 @@ export function loadAutoCookieState(
|
||||||
): { cookies: Cookie[]; origins: [] } | null {
|
): { cookies: Cookie[]; origins: [] } | null {
|
||||||
if (!isAutoCookiePersistEnabled()) return null;
|
if (!isAutoCookiePersistEnabled()) return null;
|
||||||
const file = statePath(config);
|
const file = statePath(config);
|
||||||
let parsed: AutoCookieState;
|
let raw: string;
|
||||||
try {
|
try {
|
||||||
if (!fs.existsSync(file)) return null;
|
if (!fs.existsSync(file)) return null;
|
||||||
parsed = JSON.parse(fs.readFileSync(file, 'utf-8')) as AutoCookieState;
|
raw = fs.readFileSync(file, 'utf-8');
|
||||||
|
} catch (err: any) {
|
||||||
|
// A read error here (e.g. EACCES) is NOT the benign corrupt-file case — the
|
||||||
|
// device cookie silently won't restore, so surface it rather than swallow.
|
||||||
|
console.warn(`[browse] auto-cookie state unreadable (${err?.code || err?.message}); starting without persisted cookies`);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
let parsed: AutoCookieState;
|
||||||
|
try {
|
||||||
|
parsed = JSON.parse(raw) as AutoCookieState;
|
||||||
} catch {
|
} catch {
|
||||||
return null; // corrupt — ignore (a later save will overwrite it)
|
return null; // corrupt JSON — ignore (a later save overwrites it)
|
||||||
}
|
}
|
||||||
if (!parsed || parsed.kind !== STATE_KIND || parsed.version !== STATE_VERSION) return null;
|
if (!parsed || parsed.kind !== STATE_KIND || parsed.version !== STATE_VERSION) return null;
|
||||||
if (parsed.workspaceId !== computeProfileId(config)) return null;
|
if (parsed.workspaceId !== computeProfileId(config)) return null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue