Error Handling
MediaX implements a comprehensive, typed, and event-driven error handling system with standardized validation errors, pipeline errors, and FFmpeg execution errors.
Error Classes
MediaXError
Base error class with standardized error codes
Properties:
MediaXValidationError
Parameter/input validation failures before job runs
Properties:
MediaXFFmpegError
FFmpeg execution failures with process details
Properties:
12345678910111213
Error Codes
Defined in ERROR_CODES
for strict type-safety:
Validation
Pipeline
Jobs
FFmpeg
Generic
Job-Level Error Handling
Each job emits errors via the event system:
12345678
Error Timing:
- Validation errors (MediaXValidationError) are thrown synchronously on creation
- Runtime errors (MediaXFFmpegError / MediaXError) are emitted asynchronously
Pipeline Error Handling
Pipelines centralize and normalize errors across multiple steps:
123456789101112
Pipeline Features:
Queue Error Handling
123456789101112131415161718
Error Recovery Strategies
Retry on Failure
Automatically retry failed jobs with exponential backoff
job.on("error", () => queue.add(job));
Continue on Error
Skip failed jobs and continue pipeline execution
pipeline.on("error", () => pipeline.run());
Warning Handling
Handle non-critical validation warnings gracefully
pipeline.on("warning", (warn) => log(warn));
Abort & Cleanup
Gracefully abort pipelines and clean up resources
pipeline.abort();
1234567891011121314151617181920
Best Practices
Always Attach Error Listeners
CriticalPrevent uncaught exceptions by handling all error events
Use Error Codes for Logic
ImportantUse err.code for programmatic handling (e.g., retry only on JOB_TIMEOUT)
Log FFmpeg stderr
ImportantLog stderr when catching MediaXFFmpegError for debugging
Validate Before Processing
RecommendedCheck file existence and permissions before heavy operations
Key Guidelines:
- • Always attach error listeners on both jobs and pipelines
- • Use
err.code
for programmatic handling - • Log
stderr
when catching MediaXFFmpegError - • Combine with warning events for soft failures in batch processing
- • Validate file existence and permissions before heavy operations
Common Error Scenarios
1234567891011121314151617181920212223242526272829
Build Robust Applications
With comprehensive error handling knowledge, you're ready to build production-ready applications. Explore the API reference or see practical examples.