Three defects on the paths that touch a user's real bookmarks.
**A mid-import rejection used to lose everything needed to recover.**
writeTree awaited create() and let a rejection propagate bare — while the
bookmarks it had already written sat in the user's tree, uncounted. The
neighbouring BmAborted has always carried `done` for exactly this reason.
clearRoots was worse: it is the one path that deletes, and it reported nothing
at all, plus threw BmAborted(0) on cancellation regardless of how many root
children were already gone. Both now throw BmPartialWrite{phase, done}, and the
error state carries the safety backup's filename — which `attesting` knew and
`error` threw away, so the one string that lets someone restore a half-replaced
tree was the one thing not on screen. Only when a backup was actually produced:
on a BmBackupError the file may never have been written, and sending a
frightened user to look for a backup that does not exist is worse than silence.
BmAborted is re-thrown before the wrap, with a test pinning it. Wrapping it
would relabel every user cancellation as a failure and make the `cancelled`
state — and its copy in three languages — unreachable.
**Browser Back during the backup attestation deadlocked the Manager
permanently.** The attestation resolver was a component-local `let`, so Back
unmounted ImportTab, stranded the promise runImport was awaiting, and left
isWriting() true forever: every tab and footer control disabled, beforeunload
prompting, and a remounted tab rendering two inert buttons against a fresh empty
resolver. Closing the tab was the only escape. Phase 4 closed this same hole for
the footer and the tab bar; hashchange was the door left open.
Two independent fixes, because one is not enough: startRouting now takes an
injected isBlocked predicate (injected, not imported, so route stays uncoupled
from the import session), and the resolver moved into the store where it
outlives any component. A stale or reset resolver settles **false** — an
unanswered attestation is not consent, and this is the last gate before deleting
every bookmark someone has. The restore-the-hash path has an explicit test for
not recursing; an infinite hashchange loop in a released extension, on the path
a panicking user takes, is not a defect worth discovering from a review.
**Nothing told users their imported bookmarks are re-dated to today.** docs/05
§6 instructs saying so in the import report and docs/00 §8 repeats it as a
success criterion; no string ever did. The README and store listing say it to
prospective users, and the product never said it to actual ones — so someone
migrating a decade-old archive finds every bookmark dated today with no
explanation and no way to tell it from corruption. Now shown before the import
as well as after: telling someone before they commit is worth more.
Also: a profile whose every root is policy-managed now reports
NO_WRITABLE_ROOTS rather than "the browser refused a bookmark operation". The
browser refused nothing; it is an absence, not a refusal, and the old wording
sent people looking for a permission problem that was not there.
describeError moves out of ImportTab into browser/describe-error.ts so #edit and
#export can share it next, with tests asserting the two properties that have
been defects before: it returns a key rather than a resolved sentence, and it
omits `detail` rather than setting it to undefined.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
104 lines
3.1 KiB
TypeScript
104 lines
3.1 KiB
TypeScript
/**
|
|
* Error types raised by the browser adapter layer — docs/02 §7.
|
|
*
|
|
* `core/` throws `BmParseError` and nothing else; these are the two failures
|
|
* that only exist once real effects are involved.
|
|
*/
|
|
|
|
/** Thrown when the user cancels a write. Carries exactly how many nodes landed. */
|
|
export class BmAborted extends Error {
|
|
readonly done: number;
|
|
|
|
constructor(done: number) {
|
|
super(`Import cancelled after ${done} item(s)`);
|
|
this.name = 'BmAborted';
|
|
this.done = done;
|
|
}
|
|
}
|
|
|
|
export type BmBackupErrorCode =
|
|
| 'BACKUP_SERIALIZE_FAILED'
|
|
| 'BACKUP_CANCELLED'
|
|
| 'BACKUP_WRITE_FAILED';
|
|
|
|
/**
|
|
* Thrown when the forced safety backup could not be produced or proven
|
|
* (docs/03 §1 step 6b). Deletion never proceeds past one of these.
|
|
*/
|
|
export class BmBackupError extends Error {
|
|
readonly code: BmBackupErrorCode;
|
|
|
|
constructor(code: BmBackupErrorCode, detail?: string) {
|
|
super(detail === undefined ? code : `${code}: ${detail}`);
|
|
this.name = 'BmBackupError';
|
|
this.code = code;
|
|
}
|
|
}
|
|
|
|
/** Thrown when a `chrome.*` call rejects. Keeps raw errors out of components. */
|
|
export class BmBrowserError extends Error {
|
|
readonly detail: string;
|
|
|
|
constructor(operation: string, cause: unknown) {
|
|
const detail = cause instanceof Error ? cause.message : String(cause);
|
|
super(`${operation} failed: ${detail}`);
|
|
this.name = 'BmBrowserError';
|
|
this.detail = detail;
|
|
}
|
|
}
|
|
|
|
export type BmEnvCode = 'NO_WRITABLE_ROOTS';
|
|
|
|
/**
|
|
* Thrown when the environment cannot support the operation at all.
|
|
*
|
|
* Distinct from `BmBrowserError` on purpose: an absence is not a refusal.
|
|
* Reporting "the browser refused a bookmark operation" to someone whose profile
|
|
* simply has no writable root sends them looking for the wrong thing.
|
|
*/
|
|
export class BmEnvError extends Error {
|
|
readonly code: BmEnvCode;
|
|
readonly detail: string | undefined;
|
|
|
|
constructor(code: BmEnvCode, detail?: string) {
|
|
super(detail === undefined ? code : `${code}: ${detail}`);
|
|
this.name = 'BmEnvError';
|
|
this.code = code;
|
|
this.detail = detail;
|
|
}
|
|
}
|
|
|
|
/** Which destructive step was interrupted. */
|
|
export type BmWritePhase = 'clearing' | 'writing';
|
|
|
|
/**
|
|
* Thrown when a destructive step failed part-way through.
|
|
*
|
|
* Carries exactly what already landed, for the same reason `BmAborted` carries
|
|
* `done`: a user whose tree was half-replaced needs a number and the name of
|
|
* their backup, not "the browser refused a bookmark operation".
|
|
*
|
|
* `cause` is deliberately not used — `noImplicitOverride` complicates
|
|
* redeclaring it, and the detail is flattened here anyway so the UI never has
|
|
* to unwrap a chain.
|
|
*/
|
|
export class BmPartialWrite extends Error {
|
|
readonly phase: BmWritePhase;
|
|
readonly done: number;
|
|
readonly detail: string | undefined;
|
|
|
|
constructor(phase: BmWritePhase, done: number, cause: unknown) {
|
|
const detail =
|
|
cause instanceof BmBrowserError
|
|
? cause.detail
|
|
: cause instanceof Error
|
|
? cause.message
|
|
: String(cause);
|
|
super(`${phase} failed after ${done} item(s): ${detail}`);
|
|
this.name = 'BmPartialWrite';
|
|
this.phase = phase;
|
|
this.done = done;
|
|
this.detail = detail;
|
|
}
|
|
}
|