Skip to content

Commit

Permalink
errors: skip fatal error highlighting on windows
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Hakerh400 authored and targos committed Jun 2, 2020
1 parent 762adc9 commit aca07f4
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -674,15 +674,31 @@ const fatalExceptionStackEnhancers = {
},
afterInspector(error) {
const originalStack = error.stack;
let useColors = true;
// 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. On Windows, detecting whether a console supports
// ANSI escape sequences is not reliable.
if (process.platform === 'win32') {
const info = internalBinding('os').getOSInformation();
const ver = info[2].split('.').map((a) => +a);
if (ver[0] !== 10 || ver[2] < 14393) {
useColors = false;
}
}
const {
inspect,
inspectDefaultOptions: {
colors: defaultColors
}
} = lazyInternalUtilInspect();
const colors = (internalBinding('util').guessHandleType(2) === 'TTY' &&
const colors = useColors &&
((internalBinding('util').guessHandleType(2) === 'TTY' &&
require('internal/tty').hasColors()) ||
defaultColors;
defaultColors);
try {
return inspect(error, { colors });
} catch {
Expand Down

0 comments on commit aca07f4

Please sign in to comment.