Skip to content

Errors and inert players

Copy as Markdown

loadFile and mountFile never reject. They resolve to { file } or { player }, or to { error }:

import { mountFile } from "@rupamotion/player/file";
const { player, error } = await mountFile(document.querySelector("#hero"), "/hero.rupaplay");
if (error) console.warn(error.code, error.message);
else player.play();

error.code is one of the error codes.

A wrong call to a player throws a RangeError or TypeError at your line: setSpeed(0), seek(NaN), an unknown state. Events, timers and file loads never throw.

An internal error makes that one player inert. It lets go of its listeners, timers and observers, sends error once with fatal: true, then drops its listeners. The DOM and the CSS stay, so the snippet keeps playing its CSS.

player.on("error", (event) => {
if (event.fatal) reportToMyMonitoring(event.error);
});

An inert player keeps root.rupa. Every method does nothing without an exception, except that play(state) still sets data-rupa-state, so the CSS plays the state.

destroy() is the same release without an error event.

The player has no telemetry. Forward the error event to your own monitoring if you want it.