Here is a write-up on how to implement failure options in Sharp.
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. sharp failon option
Setting failOn: 'none' was highly effective at forcing sharp to output a result even for significantly truncated JPEGs. Here is a write-up on how to implement
async function strictProcess(input) try const data, info = await sharp(input) .toBuffer( resolveWithObject: true ); Setting failOn: 'none' was highly effective at forcing
: The most relaxed setting. Sharp will attempt to process the image regardless of warnings or non-fatal errors.
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');
For modern versions, combining failOn: 'none' with the unlimited: true flag in the sharp constructor is sometimes necessary to bypass certain memory-safety or corruption checks. Implementation Example