Missing error message when destination folder does not exist
See original GitHub issuesharp is working well when the destination folder exists. But when the destination folder does not, the code crashes, with a generic error, which doesn’t state anything about the issue.
here is the code I’m using:
console.log('imgToResize', imgToResize); // C:/my/path/to/origin/my-img.jpg
console.log('img960', img960); // C:/my/path/to/960/my-img.jpg (folder "960" doesn't exist)
console.log('dimensionsFull', dimensionsFull); // { height: 1335, width: 2000, type: 'jpg' }
console.log('new dim: 960x', Math.ceil(dimensionsFull.height * 960 / dimensionsFull.width)); // 641
const sharpOptions = {
fit: 'contain',
background: {
r: 0,
g: 0,
b: 0,
alpha: 0
}
}
await sharp(imgToResize)
.resize(960, Math.ceil(dimensionsFull.height * 960 / dimensionsFull.width), sharpOptions)
.toFile(img960);
npm ERR! code ELIFECYCLE
npm ERR! errno 3221226505
npm ERR! my-app-name@0.0.0 imgmin: `node scripts/my-script.js`
npm ERR! Exit status 3221226505
npm ERR!
npm ERR! Failed at the my-app-name@0.0.0 my-script script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\my-user\AppData\Roaming\npm-cache\_logs\xxx-debug.log
The issue is solved if I add this line:
fse.ensureDirSync(path.dirname(img960));
I think sharp should check if destination folder exists at init (before sharping the actual img), and if not, throw an error which states the cause. It should be even better is sharp could make the folder if it doesn’t exists, but not sure if it should.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top Results From Across the Web
Copying files where destination folder does not exist
I find that if I remove the NewFolder/ part of the destination, the file is copied successfully. How can I get swift to...
Read more >How to Fix Destination Folder Already Exists Error in WordPress
If a folder with the same name already exists, then WordPress aborts the installation with the following error message: Destination folder already exists....
Read more >"the specified path does not exist" error - Microsoft Community
Hello, I am getting this error when I am trying to open device manager, right click on computer manager and I get this...
Read more >How To Quickly Fix Destination Folder Already Exists Error in ...
This article teaches how to quickly fix the destination folder already exists error in WordPress with actionable steps.
Read more >Destination Folder Access Denied in Windows 10/8/7 [Fixed]
The ownership of the folder or file is present with some other user account. Although the folder and files are available in your...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I added a test for this via commit https://github.com/lovell/sharp/commit/9eada2ac5a9d55574fe85e8e958087b467fad005
https://github.com/lovell/sharp/blob/9eada2ac5a9d55574fe85e8e958087b467fad005/test/unit/io.js#L800-L811
…and it crashed on Windows:
https://github.com/lovell/sharp/runs/4418122778?check_suite_focus=true
This might be a bug in libvips (or maybe glib?) - I’ll investigate.
v0.30.0 now available with libvips v8.12.2.