megahertz / electron-log

Simple logging module Electron/Node.js/NW.js application. No dependencies. No complicated configuration.
MIT License
1.27k stars 124 forks source link

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

Closed henrydf closed 1 month ago

henrydf commented 1 month ago

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.

megahertz commented 1 month ago

Thank you. I'll investigate that this week

megahertz commented 1 month ago

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.