Skip to content

console: timeEnd() doesn't throw an error if no matching label #5901

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,10 @@ Console.prototype.time = function(label) {


Console.prototype.timeEnd = function(label) {
var time = this._times.get(label);
const time = this._times.get(label);
if (!time) {
throw new Error(`No such label: ${label}`);
process.emitWarning(`No such label '${label}' for console.timeEnd()`);
return;
}
const duration = process.hrtime(time);
const ms = duration[0] * 1000 + duration[1] / 1e6;
Expand Down
10 changes: 7 additions & 3 deletions test/parallel/test-console.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
'use strict';
require('../common');
var assert = require('assert');
const common = require('../common');
const assert = require('assert');

assert.ok(process.stdout.writable);
assert.ok(process.stderr.writable);
// Support legacy API
assert.equal('number', typeof process.stdout.fd);
assert.equal('number', typeof process.stderr.fd);

assert.throws(function() {
assert.doesNotThrow(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean to delete the whole test. Just the one line that I commented on was unnecessary.

process.once('warning', common.mustCall((warning) => {
assert(/no such label/.test(warning.message));
}));

console.timeEnd('no such label');
});

Expand Down