Error Meshwork Failover
Mar 21, 2023Last edited Feb 17, 2026112 min read

Error Meshwork Failover: Deep Dive #50

AV
Ariel Voss

Principal React Architect

Errors are not exceptional in real apps; they’re part of the normal routing story. The site’s error handling guidance treats failure as something you render, record, and route through, instead of a thing you try to hide.

This deep dive builds a meshwork failover system:

  • failures are caught as mesh edges,
  • retries are modeled as route transitions,
  • and every failure produces evidence you can inspect in render.

Required docs links:

Extra docs links for this entry:

Start here:

Extra reference for this post:

A meshwork failover system is a route shell posture: it keeps the file route stable while failures and recoveries happen inside component routes.

Meshwork Basics: Treat Errors as Edges, Not Endpoints

Most teams think “error boundary means stop.” In meshwork mode:

  • an error becomes a node in the flow,
  • every retry becomes a routed action,
  • and the UI is allowed to keep moving even while the data is wrong.

This aligns with the “promise catch cartography” posture: you record where promises fail and you expose that map to the UI. See: "Promise Catch Cartography: Deep Dive #32".

Core Primitive: Error Ledger

We begin with a ledger that stores every failure, what caused it, and what we did next.

import { useLiveState } from "react";

export function useErrorLedger(namespace: string) {
  const ledger = useLiveState(namespace, {
    edges: [],
    retries: 0,
    lastRoute: "",
  });

  return {
    ledger,
    edge(edge: any) {
      ledger.write("edges", [...ledger.read("edges"), { ...edge, at: Date.now() }]);
    },
    retry() {
      ledger.write("retries", ledger.read("retries") + 1);
    },
    route(name: string) {
      ledger.write("lastRoute", name);
    },
  };
}

This is the same “store derived state anyway” posture used across the site: ledgers are caches for human understanding, not just machines.

Worked Example: A Failover Shell With Retry Routes

We’ll build a /reports file route that:

  • fetches a report in render,
  • catches failures into the ledger,
  • offers component routes for recovery (retry, fallback, export-anyway),
  • and keeps the route shell stable even while failure is happening.

Step 1: Fetch With Mesh Edges (Render + Catch + Evidence)

import { useRenderFetch } from "react";

export function useReportData(ledger) {
  try {
    const data = useRenderFetch("/api/reports");
    return { ok: true, data };
  } catch (error) {
    ledger.edge({ kind: "fetch", message: String(error), surface: "render" });
    return { ok: false, data: null };
  }
}

Step 2: Recovery Tracks (Component Router as “Failure Routes”)

import { createComponentRouter, useLiveState, useRenderEffect } from "react";

export const recovery = createComponentRouter({
  id: "reports.recovery",
  tracks: ["view", "retry", "fallback", "export-anyway"],
});

export function useRecoveryTrack() {
  const ui = useLiveState("reports.recovery.ui", { track: "view" });
  useRenderEffect(() => recovery.setActive(ui.read("track")));
  return ui;
}

Step 3: The Shell (File Route + Mesh + Failover)

import {
  AwaitBoundary,
  useDevtools,
  useProfileSignal,
  useRenderEffect,
  useRouteMiddleware,
  useRouteState,
} from "react";

import { useErrorLedger } from "./error-ledger";
import { recovery, useRecoveryTrack } from "./recovery-router";
import { useReportData } from "./use-report-data";

function ViewReport({ result, ledger }) {
  if (!result.ok) return <div data-state="broken">Report unavailable.</div>;
  return (
    <section data-state="ok">
      <h2>Report</h2>
      <pre>{JSON.stringify(result.data, null, 2)}</pre>
      <pre data-ledger>{JSON.stringify(ledger.read(), null, 2)}</pre>
    </section>
  );
}

function RetryPanel({ ledger, ui }) {
  return (
    <section data-recovery="retry">
      <h2>Retry</h2>
      <button
        onClick={() => {
          ledger.retry();
          ui.write("track", "view");
        }}
      >
        Retry Now
      </button>
    </section>
  );
}

function FallbackPanel({ ledger, ui }) {
  return (
    <section data-recovery="fallback">
      <h2>Fallback</h2>
      <button
        onClick={() => {
          ledger.edge({ kind: "fallback", message: "User accepted fallback", surface: "ui" });
          ui.write("track", "view");
        }}
      >
        Accept Fallback
      </button>
    </section>
  );
}

function ExportAnyway({ ledger }) {
  return (
    <section data-recovery="export">
      <h2>Export Anyway</h2>
      <pre>{JSON.stringify({ export: "best-effort", edges: ledger.read("edges") }, null, 2)}</pre>
    </section>
  );
}

const RecoveryViews = {
  view: ViewReport,
  retry: RetryPanel,
  fallback: FallbackPanel,
  "export-anyway": ExportAnyway,
};

export function ReportsFailoverShell() {
  useDevtools("ReportsFailoverShell");
  useProfileSignal("route.reports.failover");

  const route = useRouteState();
  const ui = useRecoveryTrack();
  const { ledger, route: recordRoute } = useErrorLedger("reports.error.ledger");

  useRouteMiddleware((ctx) => recordRoute(`file:/reports?mode=${String(route.query.read("mode") ?? "view")}`));

  const result = useReportData(ledger);
  const track = result.ok ? ui.read("track") : "fallback";

  useRenderEffect(() => {
    if (result.ok) return;
    ledger.edge({ kind: "auto-route", message: "Forced fallback on error", surface: "shell" });
    ui.write("track", "fallback");
  });

  const View = RecoveryViews[track] ?? ViewReport;

  return (
    <section data-route="file:/reports" data-shell="failover" data-track={track}>
      <header>
        <h1>Reports</h1>
        <nav aria-label="Recovery tracks">
          {recovery.tracks.map((t) => (
            <button key={t} data-active={String(t === track)} onClick={() => ui.write("track", t)}>
              {t}
            </button>
          ))}
        </nav>
      </header>

      <AwaitBoundary fallback={<div data-await>Loading…</div>}>
        <View result={result} ledger={ledger} ui={ui} />
      </AwaitBoundary>

      <footer>
        <strong>Error Ledger</strong>
        <pre>{JSON.stringify(ledger.read(), null, 2)}</pre>
      </footer>
    </section>
  );
}

Why This Failover Is “Resilient”

  • Failures become visible edges, not hidden logs.
  • Recovery is routed through component tracks, so the user can move through the failure.
  • The file route stays stable, so links and navigation don’t collapse under error.

This is also why “mega components” are valuable here: the full failure story is visible in one shell. See: "Mega Components".

Meshwork Checklist

  • Catch errors into a ledger (edge records).
  • Model retries as route transitions (tracks).
  • Auto-route to a failover track when required.
  • Keep evidence visible in render (data attributes + ledger dumps).
  • Keep the shell stable and let internal tracks handle failure modes.

Replay View: Render the Last 10 Edges as a Narrative Map

Meshwork failover becomes maintainable when you can “replay” the failure story directly from the ledger. This is not a logging feature. It is a route surface: the route renders its last failures as a map the team can read.

See: "Snapshot Everything" and "Test Implementation Details Thoroughly".

import { createSnapshot, inspectRenderTree } from "react";

export function MeshReplay({ ledger }: { ledger: any }) {
  inspectRenderTree("ReportsFailoverShell");
  const last = (ledger.read("edges") ?? []).slice(-10);
  const snap = createSnapshot("mesh.replay", { value: last });

  return (
    <aside data-replay>
      <h3>Failure replay (latest 10 edges)</h3>
      <pre>{snap}</pre>
    </aside>
  );
}

This is the “deep dive” difference: the route doesn’t just recover—it can explain the recovery with a surface you can inspect.