shbatm / MMM-Logging

Module to provide better Node.js console logging capabilities for MagicMirror²
MIT License
5 stars 3 forks source link

payload: undefined #2

Open ezar opened 5 years ago

ezar commented 5 years ago

1|MagicMir | 2019-03-10T19:05:12 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived)

Do you know why appears this message?

shbatm commented 5 years ago

What is the line immediately before it?

I can't tell if it's an actual error, or it may just be a line break. It is in the function that sends all notifications on the web console to the PM2/terminal console--it may just be a blank notification sent by another module.

ezar commented 5 years ago

Message complete:

1|MagicMir | 2019-03-11T22:21:58 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-11T22:22:24 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-11T22:22:41 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived)

ezar commented 5 years ago

Seems that you need to protect this line (34), if payload is null, no?

shbatm commented 5 years ago

It depends on which payload is causing the issue (there is a payload sent from the logging module which has a nested payload.payload from the original notification it is echoing--I should have named it differently, but that's another problem).

The parent payload shouldn't be undefined. I'll have to troubleshoot.

Do you have any errors or messages in the web console (DevTools, ctrl+shift+i)?

shbatm commented 5 years ago

Also, confirm there are no 'Module Notification:...' lines nearby the above lines?

ezar commented 5 years ago

Confirm that there are no 'Module Notification:...'

FULL STACK: 1|MagicMir | 2019-03-12T14:01:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:05:00 MMM-LocalTemperature: Socket Notification Received: "GET_DATA". (/home/pi/MagicMirror/modules/MMM-LocalTemperature/node_helper.js:43 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:05:00 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:05:00 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:10:00 MMM-LocalTemperature: Socket Notification Received: "GET_DATA". (/home/pi/MagicMirror/modules/MMM-LocalTemperature/node_helper.js:43 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:10:18 MMM-LocalTemperature: Socket Notification Received: "GET_DATA". (/home/pi/MagicMirror/modules/MMM-LocalTemperature/node_helper.js:43 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:10:18 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:10:18 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:11:51 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:15:00 MMM-LocalTemperature: Socket Notification Received: "GET_DATA". (/home/pi/MagicMirror/modules/MMM-LocalTemperature/node_helper.js:43 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:15:05 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:15:05 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:20:00 MMM-LocalTemperature: Socket Notification Received: "GET_DATA". (/home/pi/MagicMirror/modules/MMM-LocalTemperature/node_helper.js:43 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:20:08 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 1|MagicMir | 2019-03-12T14:20:08 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived)

shbatm commented 5 years ago

OK. I will troubleshoot when I get a chance. For now you can change line 33 to:

if (notification === "NOTIFICATION_TO_CONSOLE" && payload) {

ezar commented 5 years ago

Thanks! It works ;)

gonzonia commented 4 years ago

I just installed this, but I'm seeing the same error. Line 33 already matches what you have above.

Here's a section from my log where CALEXT2 is logging...

019-11-07T13:23:50 [CALEXT2] calendar:Lolly >> Scanned: 48, Selected: 48 (/home/pi/MagicMirror/modules/MMM-CalendarExt2/calendarProcessor.js:182 module.exports.parser) 2019-11-07T13:23:50 [CALEXT2] calendar:Algebra >> Scanned: 11, Selected: 11 (/home/pi/MagicMirror/modules/MMM-CalendarExt2/calendarProcessor.js:182 module.exports.parser) 2019-11-07T13:23:50 [CALEXT2] calendar:Biology >> Scanned: 7, Selected: 7 (/home/pi/MagicMirror/modules/MMM-CalendarExt2/calendarProcessor.js:182 module.exports.parser) 2019-11-07T13:23:50 [CALEXT2] calendar:English >> Scanned: 11, Selected: 11 (/home/pi/MagicMirror/modules/MMM-CalendarExt2/calendarProcessor.js:182 module.exports.parser) 2019-11-07T13:23:50 [CALEXT2] calendar:Transitions >> Scanned: 18, Selected: 18 (/home/pi/MagicMirror/modules/MMM-CalendarExt2/calendarProcessor.js:182 module.exports.parser) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived) 2019-11-07T13:23:50 MMM-Ring at (11/7/2019, 1:23:50 PM): Found 1 location(s) with 1 camera(s). (/home/pi/MagicMirror/modules/MMM-Ring/node_helper.js:169 Class.toLog)

lavolp3 commented 4 years ago

I had the same error and possibly solved it by changing line 33 to

if (notification === "NOTIFICATION_TO_CONSOLE" && payload.length) {

I THINK the reason is "payload" is a valid object therefore it is true. But its only element is "undefined". This can be solved by asking if payload has a length (a number of defined elements)

mlewus commented 4 years ago

I was getting the same error around MMM-Hotword activity. I made lavolp3’s change and it worked for me as well. Thanks!

lavolp3 commented 10 months ago

Revisiting this after several years :-) I need to say I'm not happy with my solution.

The palyoad is actually an opject that is sent from the frontend module notification system and should be properly parsed. I inserted a console.log(payload) and got this:

[31.08.2023 17:44.14.833] [LOG]   2023-08-31 17:44:14 <log> {"notification":"REGISTER_VOICE_MODULE","sender":"MMM-soccer"} (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:34 Class.socketNotificationReceived)
[31.08.2023 17:44.14.830] [LOG]   2023-08-31 17:44:14 <log>  payload: undefined (/home/pi/MagicMirror/modules/MMM-Logging/node_helper.js:35 Class.socketNotificationReceived)

Hence, the payload is there (the object containing the notification), but not properly parsed.

lavolp3 commented 10 months ago

I may have found the solution, and it could be a simple bracket thing. Following seems to work:

if (notification === "NOTIFICATION_TO_CONSOLE" && message) {
            tracer.log("Module Notification: " + message.notification + ((message.sender) ? " from " + message.sender : "") + ((message.payload) ? " payload: " + JSON.stringify(message.payload, undefined, 3) : " "));
}

Note the additional brackets I added around the message.payload condition

dathbe commented 1 month ago

I was just looking into this, and I changed payload.payload in line 34 to just payload, and it seems to give me useful information.

See #6