Fabric.js Document Engine

Search documentation

Find a page or section

中文

Error codes

View as Markdown

Every failure has a stable code you can switch on.

Every failure is a DocumentEngineError with a stable code. Document engine error codes never change within 1.x, so switch on the code and never on the message text.

import { isDocumentEngineError } from "fabricjs-document-engine";
 
try {
  await engine.load(id);
} catch (error) {
  if (isDocumentEngineError(error) && error.code === "UNSAVED_CHANGES") {
    await engine.save();
    await engine.load(id);
  }
}

Besides code, an error can carry issues, unknownTypes, missingAssets, missingFonts, problems, migrationFrom, retryable and cause.

All document engine error codes

CodeWhen
INVALID_DOCUMENTThe document shape is wrong, or the imported text is not JSON
UNSAFE_DOCUMENTAn unsafe image address, too many objects, or nesting too deep
UNSUPPORTED_SCHEMAWritten by a newer major version of this package
UNKNOWN_OBJECT_TYPEA custom class is not registered
INVALID_CUSTOM_OBJECTA registered class has no static type, or is not a Fabric.js class
MIGRATION_FAILEDAn older document could not be upgraded
LOAD_ABORTEDA newer load, or destroy, stopped this load
LOAD_FAILEDFabric.js or storage failed to load
MISSING_ASSETSImages could not be loaded
MISSING_FONTSFonts are unavailable and requireFonts is on
ASSET_UPLOAD_FAILEDThe upload handler failed
UNSAVED_CHANGESOpening another document would discard unsaved changes
STORAGE_MISSINGload, save or autosave was used without storage
SAVE_FAILEDStorage refused after all retries
SAVE_CONFLICTAnother tab or device saved first
SAVE_CANCELLEDA save was dropped because another document was opened, or the engine was destroyed
DOCUMENT_NOT_FOUNDA built-in adapter has no such document
HISTORY_FAILEDUndo or redo could not rebuild an object
RECOVERY_MISSINGRecovery is not configured
RECOVERY_NOT_FOUNDThere is no recovery copy
RECOVERY_FAILEDA recovery copy could not be written
VERSIONS_UNSUPPORTEDStorage has no version methods
VERSION_NOT_FOUNDThere is no such version
VERSION_FAILEDAn automatic version failed
INVALID_EXPORT_OPTIONSThe export options are not valid
EXPORT_BLOCKEDAn image or font would break the export. See error.problems
EXPORT_ABORTEDThe export was cancelled
EXPORT_FAILEDRendering failed
ENGINE_DESTROYEDThe engine was used after destroy()

The ones that need UI

Most document engine error codes are logged and forgotten. These need the user to decide, so give them a dialog: SAVE_CONFLICT (save conflicts), MISSING_ASSETS (images and fonts) and UNSAVED_CHANGES. A full handler is in the production checklist.