Skip to Content
GuidesError Handling

Error Handling

simple-ffmpegjs throws structured error classes so you can handle different failure modes programmatically.

Error classes

ClassWhen thrownKey properties
ValidationErrorInvalid clip configurationerrors[], warnings[] — each with code, path, message
FFmpegErrorFFmpeg command failsstderr, command, exitCode, details
MediaNotFoundErrorFile not found or unreadablepath
ExportCancelledErrorExport aborted via AbortController

Full example

try { await project.export({ outputPath: "./out.mp4" }); } catch (error) { if (error.name === "ValidationError") { error.errors.forEach((e) => console.error(`[${e.code}] ${e.path}: ${e.message}`), ); error.warnings.forEach((w) => console.warn(`[${w.code}] ${w.path}: ${w.message}`), ); } else if (error.name === "FFmpegError") { // details contains the last 50 lines of stderr, the full command, and exit code console.error("FFmpeg failed:", error.details); } else if (error.name === "MediaNotFoundError") { console.error("File not found:", error.path); } else if (error.name === "ExportCancelledError") { console.log("Export was cancelled"); } }

Validation error codes

Use ValidationCodes to match specific error types programmatically:

const { ValidationCodes } = SIMPLEFFMPEG; if (result.errors.some((e) => e.code === ValidationCodes.TIMELINE_GAP)) { // Handle gap-specific logic }

Available codes: INVALID_TYPE, MISSING_REQUIRED, INVALID_VALUE, INVALID_RANGE, INVALID_TIMELINE, TIMELINE_GAP, FILE_NOT_FOUND, INVALID_FORMAT, INVALID_WORD_TIMING, OUTSIDE_BOUNDS.

See Validation for pre-render validation patterns.

Last updated on