From 84fe73a562fb6bfc652adc7909665308accd0e3e Mon Sep 17 00:00:00 2001 From: Aditya Mukhopadhyay Date: Thu, 3 Dec 2026 01:34:07 +0530 Subject: [PATCH] Clarify browser and error documentation on v2.x --- src/browser/mod.rs | 16 +++++++++------- src/error.rs | 25 +++++++++---------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/browser/mod.rs b/src/browser/mod.rs index fcf93d77ce..6708bee3ab 100644 --- a/src/browser/mod.rs +++ b/src/browser/mod.rs @@ -137,7 +137,7 @@ impl BrowserDb { /// Queries and rules remain available; discard the handle and reopen to /// recover. Page-preparation failures retain their original engine code. /// - /// Returns a `Promise` in JavaScript. The JSON shape is: + /// Returns a `Promise` in JavaScript. The string contains one of these JSON results: /// - Query: `{"variables": [...], "results": [[...], ...]}` /// - Transact: `{"transacted": }` /// - Retract: `{"retracted": }` @@ -182,9 +182,10 @@ impl BrowserDb { /// Flush all dirty pages to IndexedDB. /// - /// Waits for every IndexedDB write applied before this call, even if it - /// has no pages of its own. Later writes are outside this boundary. Its - /// own flush failure is `[STG-048]`; an earlier failed flush is `[STG-046]`. + /// Waits for every IndexedDB write applied before this call, even if this + /// checkpoint has no pages to flush. It does not wait for later writes. + /// If this call's flush fails, it returns + /// `[STG-048]`. If an earlier flush failed, it returns `[STG-046]`. /// Discard the handle and reopen to recover. With no earlier work or dirty /// pages it resolves immediately. No-op for in-memory databases. pub async fn checkpoint(&self) -> Result<(), JsValue> { @@ -279,9 +280,10 @@ impl BrowserDb { } impl BrowserDb { - /// Reserve the durability boundary before deferring its work. Barriers - /// always resolve; the operation itself reports any error, so an internal - /// predecessor cannot cause an unhandled promise rejection. + /// Reserve the flush's place in the IndexedDB sequence synchronously, + /// before returning the JavaScript promise that does the work. Internal + /// barriers resolve even on failure, so an earlier flush cannot cause an + /// unhandled promise rejection. Each operation reports its own error. fn flush(&self, work: FlushWork) -> js_sys::Promise { let mut inner = self.inner.borrow_mut(); let Some(idb) = inner.idb.as_ref().map(IndexedDbBackend::clone_handle) else { diff --git a/src/error.rs b/src/error.rs index c2db1dc677..dd26de9ea9 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -//! Structured runtime error codes surfaced through `MinigrafError`. +//! Runtime error codes returned in `MinigrafError`. //! //! See `docs/superpowers/specs/2026-08-25-structured-error-codes-design.md` //! and `docs/ERROR_REFERENCE.md` for the design and the full code registry. @@ -241,7 +241,7 @@ pub(crate) enum ErrorCode { Int055, } -/// Single source of truth: (code, code string, message template, category). +/// The canonical list of error codes, display strings, message templates, and categories. /// /// The message template is verified against `docs/ERROR_REFERENCE.md`'s /// "Error text" lines by the sync test in this module. @@ -1452,26 +1452,19 @@ pub(crate) fn format_template(template: &str, args: &[&dyn fmt::Display]) -> Str /// An `anyhow`-compatible error carrying a compile-time-checked [`ErrorCode`]. /// -/// Built exclusively through [`bail_coded!`]/[`err_coded!`] and wrapped as an -/// `anyhow::Error`, so it rides through the crate's existing `anyhow::Result` -/// plumbing (`?`, `.context()`) unchanged. Recovered at the public API -/// boundary by [`MinigrafError::from`]`(anyhow::Error)` walking the error -/// chain for the first `CodedError` via `downcast_ref`. +/// Only [`bail_coded!`] and [`err_coded!`] build this error. They wrap it in +/// `anyhow::Error`, so `?` and `.context()` still work. At the public API, +/// [`MinigrafError::from`] uses `downcast_ref` to find the first `CodedError` +/// in the error chain. pub(crate) struct CodedError { code: ErrorCode, message: String, } impl CodedError { - /// `#[cold]`/`#[inline(never)]`: `bail_coded!`/`err_coded!` expand to a - /// call to this at every one of the (roughly 300, now that #277's six - /// category PRs have all landed) error call sites across the crate. - /// Error construction is by definition the cold path, so forcing - /// it out of line keeps the lookup + `format_template` call from being - /// duplicated inline at each one — pure binary-size cost for a path - /// that, unlike the argument-array construction immediately at the call - /// site (which still inlines, and is cheap), has no per-call-site - /// specialization to gain from inlining. + /// Keep the registry lookup and message formatting out of line so all + /// error sites share the same code. Each site still builds its own small + /// argument array. #[cold] #[inline(never)] pub(crate) fn new(code: ErrorCode, args: &[&dyn fmt::Display]) -> Self {