You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm converting a typescript project from CJS to ESM (😭) and I encountered an issue in one of my tests that uses code that uses electron-log.
In my original code base, I dynamically imported electron-log/main when it was needed, but with the ESM version of my project I now statically import it import electronLogMain from 'electron-log/main.js';. Not sure if that's related, just giving some context.
In any case, it seems electron isn't initialized in my new world like it had been and so electron.app.name or electron.app.getName() return undefined, which led to the following error message:
Unhandled electron-log error TypeError: The "path" argument must be of type string. Received undefined
at new NodeError (node:internal/errors:405:5)
at validateString (node:internal/validators:162:11)
at Object.join (node:path:1171:7)
at ElectronExternalApi.getAppLogPath (/path/to/app/node_modules/electron-log/src/node/NodeExternalApi.js:17:19)
at ElectronExternalApi.getPathVariables (/path/to/app/node_modules/electron-log/src/node/NodeExternalApi.js:95:31)
at initializeOnFirstAccess (/path/to/app/node_modules/electron-log/src/node/transports/file/index.js:84:23)
at getFile (/path/to/app/node_modules/electron-log/src/node/transports/file/index.js:117:5)
at transport (/path/to/app/node_modules/electron-log/src/node/transports/file/index.js:60:18)
at Logger.processMessage (/path/to/app/node_modules/electron-log/src/core/Logger.js:173:11)
at Logger.logData (/path/to/app/node_modules/electron-log/src/core/Logger.js:129:10)
at Object.newScope.<computed> (/path/to/app/node_modules/electron-log/src/core/scope.js:26:42)
at Object.<anonymous> (/path/to/app/node_modules/jest-mock/build/index.js:794:25)
at /path/to/app/node_modules/jest-mock/build/index.js:397:39
at Object.<anonymous> (/path/to/app/node_modules/jest-mock/build/index.js:404:13)
at Object.mockConstructor [as info] (/path/to/app/node_modules/jest-mock/build/index.js:148:19)
Digging into the electron-log code, I identified the two methods that were impacted:
Note that the super fallback is only called if an error was caught, not also if electron.app.xyz was undefined.
Expected Result
When electron.app.name or electron.app.getName() or electron.app.getVersion() return undefined then fallback to calling the super method just as when catching an error.
Actual Result
Error thrown Unhandled electron-log error TypeError: The "path" argument must be of type string. Received undefined
…ined, fixes#399 (#400)
* fix: ElectronExternalApi fallback to super when electron app is undefined; accept electron arg
* test: ElectronExternalApi fallbacks to super when electron app is undefined
* chore: Comsetic changes
Summary
👋 Hello, thanks for this great project!
I'm converting a typescript project from CJS to ESM (😭) and I encountered an issue in one of my tests that uses code that uses
electron-log
.In my original code base, I dynamically imported
electron-log/main
when it was needed, but with the ESM version of my project I now statically import itimport electronLogMain from 'electron-log/main.js';
. Not sure if that's related, just giving some context.In any case, it seems
electron
isn't initialized in my new world like it had been and soelectron.app.name
orelectron.app.getName()
return undefined, which led to the following error message:Digging into the
electron-log
code, I identified the two methods that were impacted:Note that the
super
fallback is only called if an error was caught, not also ifelectron.app.xyz
was undefined.Expected Result
electron.app.name
orelectron.app.getName()
orelectron.app.getVersion()
return undefined then fallback to calling thesuper
method just as when catching an error.Actual Result
Unhandled electron-log error TypeError: The "path" argument must be of type string. Received undefined
Versions
The text was updated successfully, but these errors were encountered: