Skip to main content

Errors

There is no editor-wide branded error hierarchy. @oh-just-another/editor itself exports no error classes โ€” failures surface as ordinary thrown Error instances, null returns, and console diagnostics. Typed errors exist where a stable contract matters: serialization.

Serialization errorsโ€‹

@oh-just-another/serialization exports two error classes:

  • DeserializationError โ€” thrown by deserializeScene / parseScene when validation fails (non-object input, document version newer than the build, schema mismatch). Carries the failure cause in reason (a z.ZodError for schema failures).
  • MissingMigrationError โ€” thrown by runMigrations when no migration is registered for a version step.
import { parseScene, DeserializationError } from "@oh-just-another/serialization";

try {
const scene = parseScene(json);
} catch (error) {
if (error instanceof DeserializationError) {
console.error("Invalid scene document", error.message, error.reason);
}
}

Null returns instead of throwsโ€‹

Operations that can legitimately produce nothing return null rather than throwing. exportSceneToPng returns null for an empty scene or when OffscreenCanvas is unavailable:

import { exportSceneToPng } from "@oh-just-another/editor";

const blob = await exportSceneToPng(scene, {
background: "color",
backgroundColor: "#ffffff",
scale: 2,
});
if (!blob) {
// empty scene or no OffscreenCanvas support
}

Diagnosticsโ€‹

  • Capability detection is logged via logCapabilities at boot, so renderer/WASM/worker misconfiguration is visible in DevTools.
  • Listener exceptions in the @oh-just-another/events emitter do not abort the emit loop โ€” remaining listeners still run and the first error is re-thrown afterwards.