Node: Unnecessary TypeError from util.inspect(Object.setPrototypeOf(function() {}, null))

Created on 21 Mar 2018  路  4Comments  路  Source: nodejs/node

  • Version: v8.9.4
  • Platform: Linux stola-ThinkPad 3.16.0-38-generic #52~14.04.1-Ubuntu SMP Fri May 8 09:43:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem: util

util.inspect(Object.setPrototypeOf(function() {}, null)) results in

TypeError: Cannot read property 'name' of null
    at formatValue (util.js:523:35)
    at Object.inspect (util.js:324:10)

Note that this is the code that is used by REPL to print the result of Object.setPrototypeOf(function() {}, null) expression.

This TypeError is confusing and unnecessary. It comes from constructor.name in util.js:523. Few lines above (line 457) there is const ctorName = ... code that attempts to avoid problems like this, i.e., it would be sufficient to use ctorName instead of constructor.name on line 523.

confirmed-bug util

Most helpful comment

It is somewhat "fixed" in master. But it will print [undefined] in this case and that is confusing as well. It should actually say [Function]. I am going to fix it in master and backport it to 9.x and maybe we can still get a backport in 8.x as well.

All 4 comments

It is somewhat "fixed" in master. But it will print [undefined] in this case and that is confusing as well. It should actually say [Function]. I am going to fix it in master and backport it to 9.x and maybe we can still get a backport in 8.x as well.

While working on this I realized that we do not really support for any data type. It is probably not possible to always show the data for all objects (e.g., Set and Map) as before but it should at least not fail.

Yes, my primary concern here is the error being thrown. We have some objects with properties similar to Object.setPrototypeOf(function() {}, null) and it is annoying to see the errors while manipulating them in REPL. Personally, I don't care about particular formatting of such objects.

Fixed by 10c850b

Was this page helpful?
0 / 5 - 0 ratings

Related issues

vsemozhetbyt picture vsemozhetbyt  路  3Comments

danialkhansari picture danialkhansari  路  3Comments

Brekmister picture Brekmister  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

fanjunzhi picture fanjunzhi  路  3Comments