Stack trace for SyntaxError hides the actual point of failure

Hi all, I've reported an issue for node-red-contrib-alexa-remote2-applestrudel where Debug panel shows me a generic error "Invalid or unexpected token" which I'm not then able to trace back to point of failure.

Even if I add a print of the stacktrace to the relevant node, it looks like maybe this aspect of NodeJS prevents me from getting a full trace.

What have you done in this case? Do I have any options here to try to investigate this error further?

Trace: Invalid or unexpected token
    at nodeError (/var/www/.node-red/node_modules/node-red-contrib-alexa-remote2-applestrudel/lib/common.js:371:17)
    at /var/www/.node-red/node_modules/node-red-contrib-alexa-remote2-applestrudel/lib/common.js:396:27
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

I found this excellent suggestion about improved error tracing when loading Nodes themselves, but it turns out that loading the Node isn't when my issue happens.

By adding the following to logging section of settings.js like this:

        callstack: {
            level: 'error',
            metrics: false,
            handler: function(conf) {
                return function(msg) {
                    e = new Error();
                    console.error(e.stack);
//                    console.trace();
                }
            }
        }

I was able to see this (still not far enough to find the underlying problem):

24 Aug 12:38:05 - [error] [alexa-remote-account:c969cb45.22f3d8] Invalid or unexpected token
Error
  at LogHandler.handler (/var/www/.node-red/settings.js:256:25)
  at LogHandler.<anonymous> (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/log.js:66:18)
  at LogHandler.emit (events.js:400:28)
  at /usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/log.js:160:21
  at Array.forEach (<anonymous>)
  at Object.log (/usr/lib/node_modules/node-red/node_modules/@node-red/util/lib/log.js:159:21)
  at Object.log (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/index.js:739:19)
  at Flow.log (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:128:21)
  at log_helper (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:498:16)
  at AlexaRemoteAccountNode.Node.error (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:527:9)

But combining Bart's idea with the Node.js file mentioned in this last callstack, I was finally able to see where this cryptic error is raised by adding console.error(msg) above this line. Would be be helpful I think to add this as well as Bart's suggestion to the master branch.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.