Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicated stack trace #20010

Closed
advanceddeveloper opened this issue Apr 13, 2018 · 4 comments
Closed

Duplicated stack trace #20010

advanceddeveloper opened this issue Apr 13, 2018 · 4 comments
Labels
question Issues that look for answers. wrong repo Issues that should be opened in another repository.

Comments

@advanceddeveloper
Copy link

  • Version: 9.11.1
  • Platform: windo 10
  • Subsystem: stack trace?

Hello. Im working on a project and experiencing weird bug. Our stack trace is duplicated, I mean it displays two times functions that I called only once. My project is very big, so we did our best to reduce it as much as we could. Here is minimal repro

"use strict";

var util = require("util");

var v1 = "example";
var v2 = [];
var v3 = null;

var closure = getClosure(v3);
var value = closure("func")(v1);
console.log(v2.length);

function getClosure(v1) {
  if(v1 === "example")
    return v1;

  try {
    v1 = `${v1.length}`;
  } catch(v2) {
    v1 = util.inspect(v2);
    v3 = v2;
  }

  var f = v2 => {
    if(v2 === "func") return f.func(v2);
    return f.obj[v1];
  };
  f.func = a => f(a && v3);
  f.obj =  {
    [v1](v2) {
      return v2.obj.length;
    }
  };

  return f;
}

It reproduces 100% of times. we tried to remove some parts of the code, but then it dont rreproduces issue.
I know this code throws error, this is because of obj is not a defined property, so it is undefined and therefore cannot read length of property obj, but it is not reason to print duplicated stack trace

My apologies for bad formatting, not very familiar with github markdown

@AyushG3112
Copy link
Contributor

Can you post what stack trace you get?

@vsemozhetbyt
Copy link
Contributor

vsemozhetbyt commented Apr 13, 2018

This is what I get from all actual versions.

Stacks:
> node.04.09.0.v8-4.5.exe test.js
test.js:31
      return v2.obj.length;
                   ^

TypeError: Cannot read property 'length' of undefined
    at f.func.f.obj.v2 (test.js:31:20)
    at Object.<anonymous> (test.js:10:28)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3

> node.06.14.0.v8-5.1.exe test.js
test.js:31
      return v2.obj.length;
                   ^

TypeError: Cannot read property 'length' of undefined
    at TypeError: Cannot read property 'length' of null
    at getClosure (test.js:18:15)
    at Object.<anonymous> (test.js:9:15)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:387:7)
    at startup (bootstrap_node.js:153:9) (test.js:31:20)
    at Object.<anonymous> (test.js:10:28)
    at Module._compile (module.js:577:32)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:387:7)
    at startup (bootstrap_node.js:153:9)

> node.08.11.0.v8-6.2.exe test.js
test.js:31
      return v2.obj.length;
                    ^

TypeError: Cannot read property 'length' of undefined
    at TypeError: Cannot read property 'length' of null
    at getClosure (test.js:18:16)
    at Object.<anonymous> (test.js:9:15)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3 (test.js:31:21)
    at Object.<anonymous> (test.js:10:28)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3

> node.09.11.1.v8-6.2.exe test.js
test.js:31
      return v2.obj.length;
                    ^

TypeError: Cannot read property 'length' of undefined
    at TypeError: Cannot read property 'length' of null
    at getClosure (test.js:18:16)
    at Object.<anonymous> (test.js:9:15)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3) (test.js:31:21)
    at Object.<anonymous> (test.js:10:28)
    at Module._compile (internal/modules/cjs/loader.js:654:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:665:10)
    at Module.load (internal/modules/cjs/loader.js:566:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:506:12)
    at Function.Module._load (internal/modules/cjs/loader.js:498:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:695:10)
    at startup (internal/bootstrap/node.js:201:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3)

> node.10.0.0.v8-6.6.2018-04-12.nightly.exe test.js
test.js:31
      return v2.obj.length;
                    ^

TypeError: Cannot read property 'length' of undefined
    at TypeError: Cannot read property 'length' of null
    at getClosure (test.js:18:16)
    at Object.<anonymous> (test.js:9:15)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3) (test.js:31:21)
    at Object.<anonymous> (test.js:10:28)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)

> node.10.0.0.v8-6.7.2018-04-11.v8-canary.exe test.js
test.js:31
      return v2.obj.length;
                    ^

TypeError: Cannot read property 'length' of undefined
    at TypeError: Cannot read property 'length' of null
    at getClosure (test.js:18:16)
    at Object.<anonymous> (test.js:9:15)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3) (test.js:31:21)
    at Object.<anonymous> (test.js:10:28)
    at Module._compile (internal/modules/cjs/loader.js:678:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
    at Module.load (internal/modules/cjs/loader.js:589:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:528:12)
    at Function.Module._load (internal/modules/cjs/loader.js:520:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:719:10)
    at startup (internal/bootstrap/node.js:228:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:575:3)

@apapirovski
Copy link
Member

apapirovski commented Apr 13, 2018

It's basically calling toString on your v2 while printing the stack trace which is now a string of the full error due to util.inspect. That's why eventually you get a line that goes something like:

at bootstrapNodeJSCore (internal/bootstrap/node.js:516:3) (/Users/apapirovski/Web/nodejs/test.js:32:21)

This would be better suited to https://github.com/nodejs/help/issues since there's no bugs or issues with Node.js core.

@bnoordhuis
Copy link
Member

Answered, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers. wrong repo Issues that should be opened in another repository.
Projects
None yet
Development

No branches or pull requests

5 participants