megahertz/electron-log

Can not log when `undefined` return by getAppName()

henrydf opened this issue ยท 2 comments

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Recently, my project can not log any more in production env. And it reports The "path" argument must be of type string. Received undefined.

Here is the diff that solved my problem:

diff --git a/node_modules/electron-log/src/node/NodeExternalApi.js b/node_modules/electron-log/src/node/NodeExternalApi.js
index 7c5359f..5257a42 100644
--- a/node_modules/electron-log/src/node/NodeExternalApi.js
+++ b/node_modules/electron-log/src/node/NodeExternalApi.js
@@ -21,7 +21,7 @@ class NodeExternalApi {
   }
 
   getAppName() {
-    return this.appName || this.getAppPackageJson()?.name;
+    return this.appName || this.getAppPackageJson()?.name || 'default';
   }
 
   /**

This issue body was partially generated by patch-package.

Thank you. I'll investigate that this week

It happens when the library can't load the app name from electron.app or package.json (there is no package.json file in the current or any parent dir). I don't want to provide a default value for this case since it isn't an expected behavior. Instead, I'm thinking about a way how app name can be configured. When that's not possible to determine it, the lib should throw a more user-friendly exception.