Skip to content

Commit

Permalink
fix: improve error message while optimizing images (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfez authored Jan 8, 2024
1 parent ee6e245 commit c167d95
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions packages/core/src/optimize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,20 @@ export type ImageFormat = keyof sharp.FormatEnum;
const tmpFile = promisify<string>(tmp.file);

export const optimizeScreenshot = async (filepath: string): Promise<string> => {
const resultFilePath = await tmpFile();
await sharp(filepath)
.resize(2048, 20480, {
fit: "inside",
withoutEnlargement: true,
})
.png({ force: true })
.toFile(resultFilePath);
return resultFilePath;
try {
const resultFilePath = await tmpFile();
await sharp(filepath)
.resize(2048, 20480, {
fit: "inside",
withoutEnlargement: true,
})
.png({ force: true })
.toFile(resultFilePath);
return resultFilePath;
} catch (error) {
const message = error instanceof Error ? error.message : "Unknown Error";
throw new Error(`Error while processing image (${filepath}): ${message}`, {
cause: error,
});
}
};

0 comments on commit c167d95

Please sign in to comment.