question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Write/read error: no such file or directory

See original GitHub issue

i have this code:

const i = await jimp.read("./img/nero.jpg");
		//const srcImage = await jimp.read("./img/v.png");
		const font = await jimp.loadFont('./font/Windlass.fnt' /*jimp.FONT_SANS_32_WHITE*/);
		await i.resize(532,392);
		await i.print(font, 50, 50, 'Hello World!', 500);
		await i.print(font, 200, 50, 'Test 2a riga', 500);
		//i.composite(srcImage, 100, 0);
		await i.write('./nero.jpg', err => console.error('write error: ', err));
		await msg.channel.send({
			files: [
			  "./nero.jpg"
			]
		});
		fs.unlinkSync('./nero.jpg');

It gives 1 time on 2, Error: ENOENT: no such file or directory, stat ‘D:\Discord Bot\gamertags-img\nero.jpg’. I tried some things, searched, but nothing works…

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
hipstersmoothiecommented, Nov 20, 2018

Basically your problem was using the callback style write instead of the promise based writeAsync

Things I changed:

  • only function on the image with async in the name are async. so only they need to be awaited, not any image manipulation operations
  • you can chain image manipulation function if you want
  • write -> writeAsync - writeAsync will actually return a promise
  • remove callback - writeAsync will throw an error and not use the callback for the error
const image = await jimp.read('./img/nero.jpg');
const font = await jimp.loadFont(
  './font/Windlass.fnt' /*jimp.FONT_SANS_32_WHITE*/
);

await image
  .resize(532, 392)
  .print(font, 50, 50, 'Hello World!', 500);
  .print(font, 200, 50, 'Test 2a riga', 500);
  .writeAsync('./nero.jpg');

await msg.channel.send({
  files: ['./nero.jpg']
});

fs.unlinkSync('./nero.jpg');
0reactions
Romans96commented, Nov 20, 2018

ok tried again changin a bit of things, and now it seems it works. The only moment where it didn’t works, was when i type the command before the bot/program hadn’t sent the image (and the fs unlinked)

Thank you so much

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error 2 for write/read access to a file - SAP Community
error 2 means "no such file or directory" so this most probably happens because of some inconsistency. You can do a consistency check:...
Read more >
No such file or directory error while execute commands from ...
The real issue is how you populate array in the first place. Consider maintaining a collection of parallel arrays, i.e. cmd[$i] would contain ......
Read more >
Unable to open /dev/sdb read-write (Read-only file system)
First try the command sudo hdparm -r0 /dev/sdb (method taken from another askubuntu answer). Then try remounting rw the partition. If these steps...
Read more >
Isilon: Shares fails to load, error "Share did not load. An ... - Dell
When we open a share that has '&' in its name, it failed to load/open via CLI and GUI. Share(s) do(es) not exist:...
Read more >
sed -i option giving error no such file or directory - Page 2
I created a shell with sed -i option. It is giving error - No such file or directory Ex - pre { overflow:scroll;...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found