Skip to content

Commit

Permalink
assert: remove code that is never reached
Browse files Browse the repository at this point in the history
The internal function `truncate()` is only called with the first
argument being the output of `util.inspect()`. `util.inspect()` calls
its own internal `formatValue()` which is guaranteed to return a string.

Therefore, we can remove the check in `truncate()` that the first
argument is a string as well as code to handle the case where it is not
a string.

PR-URL: #8132
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Alexander Makarenko <estliberitas@gmail.com>
Reviewed-By: Yorkie Liu <yorkiefixer@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
Trott authored and MylesBorins committed Oct 26, 2016
1 parent 9c826be commit 06a1c9b
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ assert.AssertionError = function AssertionError(options) {
util.inherits(assert.AssertionError, Error);

function truncate(s, n) {
if (typeof s === 'string') {
return s.length < n ? s : s.slice(0, n);
} else {
return s;
}
return s.slice(0, n);
}

function getMessage(self) {
Expand Down

0 comments on commit 06a1c9b

Please sign in to comment.