Skip to content

Crash when error.name is not a string #30572

Closed
@griffinmyers

Description

  • Version: v12.13.0.
  • Platform: Darwin will.local 18.7.0 Darwin Kernel Version 18.7.0: Sat Oct 12 00:02:19 PDT 2019; root:xnu-4903.278.12~1/RELEASE_X86_64 x86_64
  • Subsystem: internal/util/inspect.js

The following program crashes on node v12.13.0:

error-12.js
const err = new Error('bloop');
err.name = 404;
console.log(err);

with the following logged:

$ node error-12.js
internal/util/inspect.js:880
      name.endsWith('Error') &&
           ^

TypeError: name.endsWith is not a function
    at formatError (internal/util/inspect.js:880:12)
    at formatRaw (internal/util/inspect.js:681:14)
    at formatValue (internal/util/inspect.js:569:10)
    at inspect (internal/util/inspect.js:223:10)
    at formatWithOptions (internal/util/inspect.js:1651:40)
    at Object.Console.<computed> (internal/console/constructor.js:272:10)
    at Object.log (internal/console/constructor.js:282:61)
    at Object.<anonymous> (/Users/williammyers/projects/js/error-12.js:3:9)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)

On node v10.15.1, the program doesn't crash and instead logs:

$ node error-12.js
{ 404: bloop
    at Object.<anonymous> (/Users/williammyers/projects/js/error-12.js:1:75)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3) name: 404 }

I appreciate that node might not consider this a bug that is theirs to fix (the name property being non-string could be viewed as a userland error), but wanted to file the issue in case it was concerning.

I discovered this doing an upgrade to node 12--it turns out the official aws-sdk will set the name property of HTTP response errors to the numeric HTTP response code.

I suspect this was introduced in e54f237.

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions