Skip to content

Commit aca07f4

Browse files
Hakerh400targos
authored andcommitted
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 <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent 762adc9 commit aca07f4

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
@@ -674,15 +674,31 @@ const fatalExceptionStackEnhancers = {
674674
},
675675
afterInspector(error) {
676676
const originalStack = error.stack;
677+
let useColors = true;
678+
// Some consoles do not convert ANSI escape sequences to colors,
679+
// rather display them directly to the stdout. On those consoles,
680+
// libuv emulates colors by intercepting stdout stream and calling
681+
// corresponding Windows API functions for setting console colors.
682+
// However, fatal error are handled differently and we cannot easily
683+
// highlight them. On Windows, detecting whether a console supports
684+
// ANSI escape sequences is not reliable.
685+
if (process.platform === 'win32') {
686+
const info = internalBinding('os').getOSInformation();
687+
const ver = info[2].split('.').map((a) => +a);
688+
if (ver[0] !== 10 || ver[2] < 14393) {
689+
useColors = false;
690+
}
691+
}
677692
const {
678693
inspect,
679694
inspectDefaultOptions: {
680695
colors: defaultColors
681696
}
682697
} = lazyInternalUtilInspect();
683-
const colors = (internalBinding('util').guessHandleType(2) === 'TTY' &&
698+
const colors = useColors &&
699+
((internalBinding('util').guessHandleType(2) === 'TTY' &&
684700
require('internal/tty').hasColors()) ||
685-
defaultColors;
701+
defaultColors);
686702
try {
687703
return inspect(error, { colors });
688704
} catch {

0 commit comments

Comments
 (0)