Skip to content

Commit 5d80576

Browse files
Hakerh400codebytere
authored andcommittedJun 9, 2020
errors: skip fatal error highlighting on windows
Some consoles do not convert ANSI escape sequences to colors, rather display them directly to the stdout. On those consoles, libuv emulates colors by intercepting stdout stream and calling corresponding Windows API functions for setting console colors. However, fatal error are handled differently and we cannot easily highlight them. PR-URL: #33132 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent e240d56 commit 5d80576

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed
 

‎lib/internal/errors.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -669,15 +669,31 @@ const fatalExceptionStackEnhancers = {
669669
},
670670
afterInspector(error) {
671671
const originalStack = error.stack;
672+
let useColors = true;
673+
// Some consoles do not convert ANSI escape sequences to colors,
674+
// rather display them directly to the stdout. On those consoles,
675+
// libuv emulates colors by intercepting stdout stream and calling
676+
// corresponding Windows API functions for setting console colors.
677+
// However, fatal error are handled differently and we cannot easily
678+
// highlight them. On Windows, detecting whether a console supports
679+
// ANSI escape sequences is not reliable.
680+
if (process.platform === 'win32') {
681+
const info = internalBinding('os').getOSInformation();
682+
const ver = info[2].split('.').map((a) => +a);
683+
if (ver[0] !== 10 || ver[2] < 14393) {
684+
useColors = false;
685+
}
686+
}
672687
const {
673688
inspect,
674689
inspectDefaultOptions: {
675690
colors: defaultColors
676691
}
677692
} = lazyInternalUtilInspect();
678-
const colors = (internalBinding('util').guessHandleType(2) === 'TTY' &&
693+
const colors = useColors &&
694+
((internalBinding('util').guessHandleType(2) === 'TTY' &&
679695
require('internal/tty').hasColors()) ||
680-
defaultColors;
696+
defaultColors);
681697
try {
682698
return inspect(error, { colors });
683699
} catch {

0 commit comments

Comments
 (0)
Please sign in to comment.