electron: TypeError: Error processing argument at index 0, conversion failure from C:\Users\root\path\to\logo.ico
- Electron version: 1.4.3
- Operating system: Windows 10 under VirtualBox 5.0.26 r108824 running on OSX 10.11.6
Hi guys, I’m having trouble with an error that happens randomly at launch: I have an icon located at
const iconPath = "C:\Users\root\path\to\logo.ico"
And sometimes the line
const trayIcon = new Tray(iconPath)
throws the error
TypeError: Error processing argument at index 0, conversion failure from C:\Users\root\path\to\logo.ico.
Has anyone got an idea why this line sometimes throws an error and sometimes works properly, with the ico file being strictly the same ?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 38
- Comments: 31 (5 by maintainers)
Commits related to this issue
- fix(electron): correct resize logic avoid setBound TypeError: https://github.com/electron/electron/issues/7657 — committed to azu/faao by azu 5 years ago
- Use native image * https://github.com/electron/electron/issues/7657 — committed to ankurk91/google-chat-electron by ankurk91 4 years ago
- Use native image * https://github.com/electron/electron/issues/7657 — committed to wac925/google-chat-electron by wac925 4 years ago
You can specify an absolute path. like this:
Thanks @isNeilLin ,but it’s still not working correctly even if I’ve specified an absolute path. Do you have any other workaround?
If you are a Windows user, the problem had nothing to do with the image path but rather the setBounds values. The short of it is you must parseInt the values for the coordinates. This works for me:
@littletinman You have to pass the TrayIcon a native image object. what you are passing is a STRING instead of nativeImage:
In that way the trayIcon will work
In case someone ends up here without finding a solution that works, here are the steps I’d recommend:
Trayconstructor? If not:Why was this issue closed? This bug exists in Electron 8.2.3 (macosx), the latest version released just 4 days ago.
This error happens when the icon does not exist for any reason, throwing exception for this was a decision made on the first day and I’m still not sure whether it is a good design.
Anyway if you want to ignore this error you can use
naitveImageto create an icon from path and then pass it toTray, and it silences the error.This issue is extremely annoying on both windows and macos. The icon files need to be crafted with magic spells, and randomly stop working once every couple electron updates. The image handling code should be re-written. For example, if you have 1024x1024 icon in .ico it wont work - WHY? Just discard the icon you dont need and not crash the entire application during startup. I know ico should not include icon of this size but this is an unnecessary bug that has been around forever.
@ue / @JoeGrasso Had the same problem and
Math.floorfixed it:I can confirm that the issue was missing Math.floor and sending floating numbers to window
replaced with
We are calculating position to put 2 windows in center next to each other, and it could happen the numbers were floating point numbers and not whole. Crashes only on Windows. Rounding the numbers fixed the issue.
I’m having this issue on Windows 10 only after building the electron app for deployment.
Versions
Code
I was able to solve it figuring out if the file exists in the project files or not. for that I have first to verify the existence of the file, then convert the image as nativeImage. I’m using fs-jetpack to verify quickly if it is “file” the output of the console… The problem is that likely you guys are pointing to a file where the app doesn’t have access…