# Stack trace for SyntaxError hides the actual point of failure

**URL:** https://discourse.nodered.org/t/stack-trace-for-syntaxerror-hides-the-actual-point-of-failure/50117
**Category:** General
**Created:** [24 August 2021 16:05 UTC](https://discourse.nodered.org/t/stack-trace-for-syntaxerror-hides-the-actual-point-of-failure/50117 "2021-08-24T16:05:48Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![lowlyocean](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lowlyocean/32/46547_2.png) [@lowlyocean](https://discourse.nodered.org/u/lowlyocean)
#### Post date: [24 August 2021 16:05 UTC](https://discourse.nodered.org/t/stack-trace-for-syntaxerror-hides-the-actual-point-of-failure/50117/1 "2021-08-24T16:05:48Z")

</div>

Hi all, I've reported [an issue](https://github.com/bbindreiter/node-red-contrib-alexa-remote2-applestrudel/issues/9) 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](https://github.com/nodejs/node/issues/11865) 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?

```auto
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)

```

---

<div class="post-metadata">

### Author: ![lowlyocean](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lowlyocean/32/46547_2.png) [@lowlyocean](https://discourse.nodered.org/u/lowlyocean)
#### Post date: [24 August 2021 16:45 UTC](https://discourse.nodered.org/t/stack-trace-for-syntaxerror-hides-the-actual-point-of-failure/50117/2 "2021-08-24T16:45:44Z")

</div>

I found [this excellent suggestion](https://discourse.nodered.org/t/how-to-get-errors-exceptions-while-developing-custom-node/23830/3) 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:

```auto
        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):

```auto
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](https://github.com/node-red/node-red/blob/master/packages/node_modules/@node-red/runtime/lib/nodes/Node.js#L526). Would be be helpful I think to add this as well as Bart's suggestion to the master branch.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [23 October 2021 16:46 UTC](https://discourse.nodered.org/t/stack-trace-for-syntaxerror-hides-the-actual-point-of-failure/50117/3 "2021-10-23T16:46:21Z")

</div>

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