Handle failures
Route typed validation, resolution, import, and positional export failures without partial output.
import { AssimpError, type AssimpFailureCode } from 'libassimp';
const remedy = (error: AssimpError): string => {
const remedies: Record<AssimpFailureCode, string> = {
NO_FILES: 'Supply an entry file.',
UNSUPPORTED_FORMAT: 'Choose an edge compiled into this entry.',
INVALID_OPTIONS: 'Correct the named option paths.',
RESOLVE_FAILED: `Retry or replace the source for ${error.fileName ?? 'the sidecar'}.`,
IMPORT_FAILED: 'Correct the entry bytes/name or supply a required sidecar.',
EXPORT_FAILED: `Correct target ${error.formatIndex ?? 0} (${error.format ?? 'unknown'}).`,
};
return remedies[error.code];
};
console.log(remedy(new AssimpError('NO_FILES', 'convert needs at least one input file.')));INVALID_OPTIONS is raised before Wasm for unknown/inapplicable fields, wrong kinds, bounds, duplicate steps, and conflicts. RESOLVE_FAILED preserves the exact requested fileName and the thrown/rejected value as cause.
Plural target failures carry zero-based formatIndex and canonical format. Results are atomic: if a later exporter fails, no earlier output is returned.
import { AssimpError, convertFormats } from 'libassimp';
try {
await convertFormats(
{ name: 'model.glb', bytes: new Uint8Array() },
{ targets: [{ to: 'stl' }, { to: '3mf' }] },
);
} catch (error) {
if (error instanceof AssimpError) {
console.error(error.code, error.formatIndex, error.format, error.fileName);
}
}Binary loading/instantiation failures and calls after disposal are plain errors rather than conversion failures. A rejected queued conversion does not poison later jobs on the same live instance.