Skip to content

doc:Error:captureStackTrace description inaccurate #5675

@pabigot

Description

@pabigot

From at least Node 4.2 the documentation says:

The first line of the trace, instead of being prefixed with ErrorType: message, will be the result of calling targetObject.toString().

This test program:

var assert = require('assert');

function X(msg) {
  this.message = msg;
}
X.prototype.name = 'X';
X.prototype.toString = function() { return 'toString'; }

var x = new X('something');
assert.deepEqual(x, {message: 'something'});
assert.equal(x.toString(), 'toString');

Error.captureStackTrace(x);
assert.equal(x.stack.split('\n')[0], 'X: something');

proves the description incorrect. The first line is produced by deps/v8/src/messages.js in ErrorToStringDetectCycle from the name and message properties of targetObject with this logic:

if (name === "") return message;
if (message === "") return name;
return name + ": " + message;

where name defaults to "Error" and message defaults to "".

I'm not good at user-facing technical documentation so I'd rather not try to craft replacement text for something that complex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    docIssues and PRs related to the documentations.good first issueIssues that are suitable for first-time contributors.wipIssues and PRs that are still a work in progress.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions