The is a small but powerful lever for developers. By choosing the right level of strictness, you can balance the need for high-volume processing with the necessity of server stability and output quality. For most production environments, starting with warning is a best practice to ensure your image pipeline remains "sharp" and reliable. Files | Directus Docs
| Goal | Implementation Strategy | | :--- | :--- | | | Wrap sharp() call in try/catch (standard error handling). | | Fail on truncated data | Check info.truncated in the callback/buffer return object. | | Fail on dimensions | Run .metadata() first, then throw custom error based on width/height. | | Fail on oversized files | Use the .limitInputPixels() option. |
async function processImage(input) try // If 'input' is not a valid image, sharp will throw an error here const data = await sharp(input) .resize(300, 300) .toFile('output.png'); sharp failon option
The failOn setting only takes effect after the image format is identified. If the first few "magic bytes" of a file (e.g., the PNG header) are missing or wrong, sharp will throw an "unsupported image format" error before failOn can be applied.
Note: If "sharp failon option" refers to a specific CLI tool or a different software library not mentioned here, please provide additional context regarding the technology stack. The is a small but powerful lever for developers
The failOn option determines the "strictness" of the Sharp instance when it encounters problems with input image metadata or pixel data. By default, Sharp is designed to be resilient, often attempting to process images even if they have minor technical flaws.
Sometimes an image has valid metadata (width/height) but corrupted pixel data. Using failOn: 'warning' (default) is the safest way to validate that an image is fully processable before storing it. If you'd like to explore this further, I can provide: A performance comparison between different failOn levels. A guide on validating user uploads using this option. Troubleshooting steps for specific VipsJpeg errors . Truncated JPGs And Sharp Version · Issue #3624 - GitHub Files | Directus Docs | Goal | Implementation
: The most relaxed setting. Sharp will attempt to process the image regardless of warnings or non-fatal errors.