stablyai/orca · error · AggregateError
Could not restore replaced cookies
Error message
Could not restore replaced cookies
What it means
Thrown as an AggregateError by restoreImportedDomainCookies when one or more store.set() calls to re-write previously-removed cookies failed. The function iterates a list of cookies, attempts to re-set each via Electron's Cookies.set(), collects failures, and if any failed, throws all collected errors aggregated. Each failure's underlying cause is an Electron cookie-set rejection (malformed cookie, invalid domain, etc.).
Source
Thrown at src/main/browser/browser-cookie-import-policy.ts:193
continue
}
await store.set({
url,
name: cookie.name,
value: cookie.value,
...(cookie.hostOnly ? {} : { domain: cookie.domain }),
...(cookie.path ? { path: cookie.path } : {}),
secure: cookie.secure,
httpOnly: cookie.httpOnly,
sameSite: cookie.sameSite,
...(cookie.expirationDate ? { expirationDate: cookie.expirationDate } : {})
})
} catch (err) {
failures.push(err)
}
}
if (failures.length > 0) {
throw new AggregateError(failures, 'Could not restore replaced cookies')
}
}
type CookieClearSession = {
cookies: Pick<Cookies, 'get' | 'set'>
clearStorageData: Session['clearStorageData']
}
async function restoreCookieClearSnapshot(
store: Pick<Cookies, 'set'>,
snapshot: readonly Cookie[],
originalError: unknown,
rollbackMessage: string
): Promise<never> {
try {
await restoreImportedDomainCookies(store, snapshot)
} catch (rollbackError) {
throw new AggregateError([originalError, rollbackError], rollbackMessage)View on GitHub (pinned to 1136503c6a)
Solutions
- Inspect the AggregateError's errors array — each entry is a specific Electron cookie-set rejection with the cookie that failed.
- Validate cookie attributes (domain, path, sameSite, secure, httpOnly, expirationDate) against Electron's Cookies.set() constraints before attempting a restore.
- For sameSite=None cookies, ensure secure=true is set; for hostOnly cookies, omit the domain field.
- If restore is best-effort, catch the AggregateError and log which cookies couldn't be restored rather than failing the whole import.
Defensive patterns
Strategy: try-catch
Validate before calling
import type { Cookie } from 'electron'
function cookieIsValidForSet(cookie: Partial<Cookie>): boolean {
if (cookie.sameSite === 'no restriction' && !cookie.secure) return false
if (!cookie.name || cookie.name.length === 0) return false
return true
} Type guard
function isAggregateError(e: unknown): e is AggregateError {
return e instanceof AggregateError && Array.isArray(e.errors)
} Try / catch
try {
await restoreImportedDomainCookies(store, cookies)
} catch (e) {
if (e instanceof AggregateError) {
// best-effort restore failed — log which cookies couldn't be re-set
for (const err of e.errors) console.error('Cookie restore failed:', err)
// decide whether to surface or swallow based on whether partial jar is acceptable
}
throw e
} Prevention
- Validate cookie attributes against Electron's Cookies.set() constraints before restore (sameSite=None requires secure, hostOnly requires no domain)
- Normalize cookie domains consistently between removal and restore
- Test cookie round-trip with the target Electron version — validation strictness varies
When it happens
Trigger: restoreImportedDomainCookies is called during cookie rollback (after a failed removal in replaceCookiesForImportedDomains, or after a bulk clear in bulkClearCookiesExcept). One or more cookies in the restore list fail store.set() — e.g. a cookie whose domain is malformed after normalization, a secure cookie set on an http URL, an httpOnly constraint violation, or an expired/invalid expirationDate. The cookieRemovalUrl or normalizeCookieDomain for a given cookie produced a valid URL but set() still rejected the cookie details.
Common situations: Rollback after a partial cookie-domain replacement where the original cookies had attributes (sameSite, secure, domain) that Electron rejects on re-set; cookies with problematic sameSite=None+secure interplay; a cookie whose domain normalization changed between removal and restore; Electron version differences in cookie validation strictness.
Related errors
- Cookie replacement and rollback failed
- [plain-node-entry-guard] "${entryName}" reaches chunk "${chu
- Electron did not expose GC; keep --js-flags=--expose-gc in t
- Electron trial failed (${result.error?.message ?? result.sig
- Electron trial did not report a result (status ${result.stat
AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12).
Data as JSON: /api/errors/e351f9a8320e46f3.
Report an issue: GitHub.