Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

1.5 KB
Raw Blame
/**
 * Turning a 3D asset failure into something a person can act on.
 *
 * The raw messages are useless on their own: the glTF parser JSON.parses
 * whatever bytes it is handed, so a 200 HTML body (an SPA fallback answering a
 * path that isn't really served) surfaces as a JSON syntax error naming a `<`
 * token. Shared rather than private to the GLB viewer because the CoS avatars
 * load remote GLBs too, and a model 404 there used to be reported as "this
 * display has no WebGL" — sending the user to change an unrelated setting.
 */

// One table so every recognized cause reads the same way everywhere.
const FAILURE_HINTS = [
  [
    /Unexpected token '<'|<!DOCTYPE/i,
    'The server answered with a web page instead of the mesh file — the asset may be missing or the server may still be restarting.',
  ],
  [/webgl/i, 'This display cannot create a WebGL context, so 3D previews cannot render here.'],
  [/\b404\b|not found/i, 'The mesh file is no longer on disk.'],
];

/** The error's message, whatever shape the thrower used. */
export const glbErrorText = (error) => String(error?.message || error || '');

/**
 * A sentence naming the cause, or `null` when nothing here recognizes it —
 * deliberately not a generic catch-all string, so a caller can tell "we know
 * what went wrong" from "we don't" and render accordingly.
 */
export function glbFailureHint(error) {
  const message = glbErrorText(error);
  return FAILURE_HINTS.find(([pattern]) => pattern.test(message))?.[1] || null;
}