| 74 | 74 | * Read the image, resize, and save it as a PNG into the buffer. |
| 75 | 75 | * @returns {Promise<Buffer>} Image buffer |
| 76 | 76 | */ |
| 77 | 77 | async function getInputImage() { |
| 78 | + try { |
| 78 | 79 | if (Buffer.isBuffer(inputFile)) { |
| 79 | 80 | return await parseImageBuffer(inputFile, crop); |
| 80 | 81 | } |
| 81 | 82 | |
| 82 | 83 | return await tryReadImage(inputFile, crop); |
| 84 | + } catch (error) { |
| 85 | + const message = Buffer.isBuffer(inputFile) ? 'Failed to read image buffer.' : `Failed to read image: ${inputFile}.`; |
| 86 | + console.warn(message, 'Using a fallback image.', error); |
| 87 | + return await fs.promises.readFile(defaultAvatarPath); |
| 88 | + } |
| 83 | 89 | } |
| 84 | 90 | |
| 85 | 91 | const inputImage = await getInputImage(); |