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 <[email protected]>
Reviewed-By: Alexander Makarenko <[email protected]>
Reviewed-By: Yorkie Liu <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
Trott authored and rvagg committed Oct 18, 2016
1 parent ec442d9 commit 6fdcd7a
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 6fdcd7a

Please sign in to comment.