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

Misleading error message #24917

Closed
lpinca opened this issue Dec 9, 2018 · 2 comments
Closed

Misleading error message #24917

lpinca opened this issue Dec 9, 2018 · 2 comments
Labels
assert Issues and PRs related to the assert subsystem. confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.

Comments

@lpinca
Copy link
Member

lpinca commented Dec 9, 2018

  • Version: v11.4.0
  • Platform: macOS
  • Subsystem: assert
$ cat t.js 
const assert = require('assert');

function StorageObject() {}
StorageObject.prototype = Object.create(null);

assert.deepStrictEqual(new StorageObject(), {});
$ node t.js 
assert.js:86
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Values identical but not reference-equal:

{}

    at Object.<anonymous> (/Users/luigi/t.js:6:8)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:776:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)
    at startExecution (internal/bootstrap/node.js:276:5)
    at startup (internal/bootstrap/node.js:227:5)

The assertion fails because the objects have a different prototype. The same assertion produces a different message in other cases, for example:

$ cat t.js 
const assert = require('assert');

assert.deepStrictEqual(Object.create(null), {});
$ node t.js 
assert.js:86
  throw new AssertionError(obj);
  ^

AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected

+ [Object: null prototype] {}
- {}
    at Object.<anonymous> (/Users/luigi/t.js:3:8)
    at Module._compile (internal/modules/cjs/loader.js:723:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
    at Module.load (internal/modules/cjs/loader.js:620:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
    at Function.Module._load (internal/modules/cjs/loader.js:552:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:776:12)
    at executeUserCode (internal/bootstrap/node.js:342:17)
    at startExecution (internal/bootstrap/node.js:276:5)
    at startup (internal/bootstrap/node.js:227:5)

cc: @BridgeAR

@lpinca lpinca added the assert Issues and PRs related to the assert subsystem. label Dec 9, 2018
@BridgeAR BridgeAR added confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module. labels Dec 10, 2018
@BridgeAR
Copy link
Member

@lpinca do you have a suggestion how the first object should look like? I am struggling a bit finding a good representation. It's not the objects prototype that is null but the objects prototype itself has a null prototype.

One way could of course be to special handle this in assert directly but that would require quite some work around to make that happen.

@lpinca
Copy link
Member Author

lpinca commented Dec 11, 2018

I honestly don't know, can't think of a good representation :)

BridgeAR added a commit to BridgeAR/node that referenced this issue Dec 11, 2018
It is currently difficult to distinguish multiple objects from each
other because the prototype is not properly inspected. From now on
all prototypes will be inspected, even if we do not fully know how
they will look like / what their shape really is.

Fixes: nodejs#24917
BethGriggs pushed a commit that referenced this issue Dec 18, 2018
It is currently difficult to distinguish multiple objects from each
other because the prototype is not properly inspected. From now on
all prototypes will be inspected, even if we do not fully know how
they will look like / what their shape really is.

PR-URL: #24974
Fixes: #24917
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
refack pushed a commit to refack/node that referenced this issue Jan 14, 2019
It is currently difficult to distinguish multiple objects from each
other because the prototype is not properly inspected. From now on
all prototypes will be inspected, even if we do not fully know how
they will look like / what their shape really is.

PR-URL: nodejs#24974
Fixes: nodejs#24917
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Anto Aravinth <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. confirmed-bug Issues with confirmed bugs. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants