3

I'm currently running console.log on a variable like so:

console.log(runnable);

When I look in the console I see this data:

enter image description here

I want to access the runnable.err key however the console returns undefined.

After this I tried to use console.log(JSON.stringify(runnable)); however I got the following error:

TypeError: Converting circular structure to JSON

When researching how to convert the circular structure all I can find is ways to parse the data safely without including the circular data. Is there any way I can access this data? Unfortunately I can't alter the data.

Thanks

Nick Maddren
  • 661
  • 4
  • 8
  • 20
  • Did you try targeting your error more precisely? `console.log(runnable.err.message)` – Zenoo Mar 26 '18 at 08:53
  • @Zenoo how can one log property message of undefined? – Laurens Mäkel Mar 26 '18 at 08:55
  • @LaurensMäkel Doesn't seem undefined to me in the Chrome DevTools, unless it is populated later on. – Zenoo Mar 26 '18 at 08:56
  • Sorry I forgot to mention that I had tried going a layer deeper like so `runnable.err.message` returns undefined. – Nick Maddren Mar 26 '18 at 08:57
  • @zenoo well op mentioned he tried logging err but it returned undefined, there is no way that err.message will be defined when err is undefined :/ .. I can see its in Dev tools showing up, but that's exactly op his question – Laurens Mäkel Mar 26 '18 at 10:12
  • How is this a duplicate? The question is an example of an XY problem (OP think they want to do X but actually wants to do Y). – wizzwizz4 Jul 21 '19 at 11:09

1 Answers1

4

I think what's happening here is that runnable doesn't have a .err property when you call console.log(runnable) but a .err property is added later.

Using console.log() on objects can behave strangely (showing the current state of the object instead of the state when logged). See console.log() shows the changed value of a variable before the value actually changes

To test that hypothesis, try changing

console.log(runnable.err);

to

setTimeout(function() {
    console.log(runnable.err);
}, 1000);

and see if it's no longer undefined.

Rocky Sims
  • 3,523
  • 1
  • 14
  • 19