2

In only a specific object, when I use console.log or I print the result of util.inspect I got just the number 1 or 2 as the result.

How do I now that the object printed is not just the number 1 or 2? I use the debugger inspector to see the attributes and functions, also it's possible to run some code to check all the members of the object, described in Node.js console.log(object) prints empty object.

NOTE: I tried to clone/copy the object and I'm getting the same behavior, what's is wrong with that object?

I'm using this library: https://hexo.io/

When I tried to use this feature: https://hexo.io/api/renderer.html

Code example:

hexo.extend.renderer.register('some', 'html', function (data, options, callback) {

    console.log("Data");
    console.log(data); // It works (object is printed sucessfully)
    console.log("Options");
    console.log(options); // I got "2" printed.

    // something unrelated code to use the callback

}, false);

Like I said the object options have several different members, and is the same/similar behavior with util.inspect, even if I specified depth and/or other parameters.

My purpose is to find why does it happen, and how to fix it?

EDIT:

In addition, if I try to serialize this object into JSON, using JSON.stringify, that's the exception that I'll receive:

Unhandled rejection TypeError: Converting circular structure to JSON
    at Object.stringify (native)
Community
  • 1
  • 1
J. Lennon
  • 3,311
  • 4
  • 33
  • 64
  • I don't know how to help you, but have you tried to see the typeof() the options? This could clean things up. – Rodmentou Nov 04 '15 at 01:52
  • @RodrigoSouza the result is object. – J. Lennon Nov 04 '15 at 02:09
  • What does `console.log(arguments)` print? – laggingreflex Nov 04 '15 at 02:10
  • try to alter the function parameter name `function (data_r, options_r, callback_r) {` then `console.log(options_r);` what came out? – aswzen Nov 04 '15 at 02:14
  • @laggingreflex I got just a number for that buggy object, the same behavior as reported. For the other arguments, the objects are printed normally. – J. Lennon Nov 04 '15 at 02:14
  • @aswzen same behavior, the second argument always is printed incorrectly. – J. Lennon Nov 04 '15 at 02:17
  • maybe its a bug from hexo itself... try to use another version of hexo or look up your code above the register maybe you just set the value to 2, that is all i can help – aswzen Nov 04 '15 at 02:23
  • So just to review, this code: `console.log(typeof options, options, options.prop)` (where prop is a known property) will print: `object 2 propvalue` Is that right? If so, I must say it's very weird. – laggingreflex Nov 04 '15 at 15:49
  • I would dig through the hexo source in node_modules to find where that `hexo.extend.renderer.register` is defined because it must be generating that `options` object to see what its doing to it. – laggingreflex Nov 04 '15 at 15:49
  • @laggingreflex thanks for the help. The result of ``console.log(typeof options, options, options.cache)`` was ``object 2 false`` I believe that the problem is some circular structure inside of that object. It will require some tests in separated environment just with ``console.log`` to see how it behaves – J. Lennon Nov 04 '15 at 22:36

0 Answers0