8000 Clarify browser and error documentation on v2.x by adityamukho · Pull Request #985 · project-minigraf/minigraf · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions src/browser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>` in JavaScript. The JSON shape is:
/// Returns a `Promise<string>` in JavaScript. The string contains one of these JSON results:
/// - Query: `{"variables": [...], "results": [[...], ...]}`
/// - Transact: `{"transacted": <tx_id>}`
/// - Retract: `{"retracted": <tx_id>}`
Expand Down Expand Up @@ -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> {
Expand Down Expand Up @@ -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 {
Expand Down
25 changes: 9 additions & 16 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
Loading
0