Skip to content

Commit

Permalink
Stop setting potentially non-string name properties on Errors (#2963)
Browse files Browse the repository at this point in the history
For example, extractError in query.js, when given a bare (bodyless)
response, will pass the (numeric) httpResponse statusCode as the
`code` option to util.error. util.error then sets the `name` property
of the Error from this. The result is that property ends up as a number,
but is required to a string; nodejs calls endsWith() on it
https://github.com/nodejs/node/blob/e5d3c8121dd0bcc4dbf52c7b3a0521e359363a05/lib/internal/util/inspect.js#L922
, so will throw an exception if an Error with a non-string name is
ever inspected.
  • Loading branch information
SimonWoolf authored and ajredniwja committed Jan 10, 2020
1 parent 4ee5314 commit c2ad3ef
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-util-358e56d3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "util",
"description": "Fix `name.endsWith is not a function` exception when inspecting some generated errors with some versions of nodejs"
}
2 changes: 1 addition & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ var util = {
Object.defineProperty(err, 'message', {enumerable: true});
}

err.name = options && options.name || err.name || err.code || 'Error';
err.name = String(options && options.name || err.name || err.code || 'Error');
err.time = new Date();

if (originalError) err.originalError = originalError;
Expand Down

0 comments on commit c2ad3ef

Please # to comment.