Skip to content

Commit 117b482

Browse files
committed
Handle Windows crash resets in wrappers
1 parent 76c5879 commit 117b482

3 files changed

Lines changed: 75 additions & 9 deletions

File tree

cli/release-staging/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ function resetTerminal(options = {}) {
5656
}
5757
}
5858

59+
function getUnsignedExitCode(code) {
60+
return code != null && code < 0 ? (code >>> 0) : code
61+
}
62+
63+
function isWindowsNativeCrashCode(code) {
64+
const unsignedCode = getUnsignedExitCode(code)
65+
return (
66+
process.platform === 'win32' &&
67+
(unsignedCode === 0xC000001D ||
68+
unsignedCode === 0xC0000005 ||
69+
unsignedCode === 0xC0000409)
70+
)
71+
}
72+
73+
function shouldExitAlternateScreen(code, signal) {
74+
return Boolean(signal) || isWindowsNativeCrashCode(code)
75+
}
76+
5977
function createConfig(packageName) {
6078
const homeDir = os.homedir()
6179
const configDir = path.join(homeDir, '.config', 'manicode')
@@ -485,7 +503,9 @@ async function checkForUpdates(runningProcess, exitListener) {
485503
})
486504

487505
newChild.on('exit', (code, signal) => {
488-
resetTerminal({ exitAlternateScreen: Boolean(signal) })
506+
resetTerminal({
507+
exitAlternateScreen: shouldExitAlternateScreen(code, signal),
508+
})
489509
printCrashDiagnostics(code, signal)
490510
process.exit(signal ? 1 : (code || 0))
491511
})
@@ -504,7 +524,7 @@ async function checkForUpdates(runningProcess, exitListener) {
504524

505525
function printCrashDiagnostics(code, signal) {
506526
// Windows NTSTATUS codes (unsigned DWORD)
507-
const unsignedCode = code != null && code < 0 ? (code >>> 0) : code
527+
const unsignedCode = getUnsignedExitCode(code)
508528
const isIllegalInstruction =
509529
signal === 'SIGILL' ||
510530
(process.platform === 'win32' && unsignedCode === 0xC000001D)
@@ -566,7 +586,9 @@ async function main() {
566586
})
567587

568588
const exitListener = (code, signal) => {
569-
resetTerminal({ exitAlternateScreen: Boolean(signal) })
589+
resetTerminal({
590+
exitAlternateScreen: shouldExitAlternateScreen(code, signal),
591+
})
570592
printCrashDiagnostics(code, signal)
571593
process.exit(signal ? 1 : (code || 0))
572594
}

cli/release/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ function resetTerminal(options = {}) {
5656
}
5757
}
5858

59+
function getUnsignedExitCode(code) {
60+
return code != null && code < 0 ? (code >>> 0) : code
61+
}
62+
63+
function isWindowsNativeCrashCode(code) {
64+
const unsignedCode = getUnsignedExitCode(code)
65+
return (
66+
process.platform === 'win32' &&
67+
(unsignedCode === 0xC000001D ||
68+
unsignedCode === 0xC0000005 ||
69+
unsignedCode === 0xC0000409)
70+
)
71+
}
72+
73+
function shouldExitAlternateScreen(code, signal) {
74+
return Boolean(signal) || isWindowsNativeCrashCode(code)
75+
}
76+
5977
function createConfig(packageName) {
6078
const homeDir = os.homedir()
6179
const configDir = path.join(homeDir, '.config', 'manicode')
@@ -502,7 +520,9 @@ async function checkForUpdates(runningProcess, exitListener) {
502520
const newChild = spawnInstalledBinary({ detached: false })
503521

504522
newChild.on('exit', (code, signal) => {
505-
resetTerminal({ exitAlternateScreen: Boolean(signal) })
523+
resetTerminal({
524+
exitAlternateScreen: shouldExitAlternateScreen(code, signal),
525+
})
506526
printCrashDiagnostics(code, signal)
507527
process.exit(signal ? 1 : (code || 0))
508528
})
@@ -516,7 +536,7 @@ async function checkForUpdates(runningProcess, exitListener) {
516536

517537
function printCrashDiagnostics(code, signal) {
518538
// Windows NTSTATUS codes (unsigned DWORD)
519-
const unsignedCode = code != null && code < 0 ? (code >>> 0) : code
539+
const unsignedCode = getUnsignedExitCode(code)
520540
const isIllegalInstruction =
521541
signal === 'SIGILL' ||
522542
(process.platform === 'win32' && unsignedCode === 0xC000001D)
@@ -634,7 +654,9 @@ async function main() {
634654
const child = spawnInstalledBinary()
635655

636656
const exitListener = (code, signal) => {
637-
resetTerminal({ exitAlternateScreen: Boolean(signal) })
657+
resetTerminal({
658+
exitAlternateScreen: shouldExitAlternateScreen(code, signal),
659+
})
638660
printCrashDiagnostics(code, signal)
639661
process.exit(signal ? 1 : (code || 0))
640662
}

freebuff/cli/release/index.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ function resetTerminal(options = {}) {
5656
}
5757
}
5858

59+
function getUnsignedExitCode(code) {
60+
return code != null && code < 0 ? (code >>> 0) : code
61+
}
62+
63+
function isWindowsNativeCrashCode(code) {
64+
const unsignedCode = getUnsignedExitCode(code)
65+
return (
66+
process.platform === 'win32' &&
67+
(unsignedCode === 0xC000001D ||
68+
unsignedCode === 0xC0000005 ||
69+
unsignedCode === 0xC0000409)
70+
)
71+
}
72+
73+
function shouldExitAlternateScreen(code, signal) {
74+
return Boolean(signal) || isWindowsNativeCrashCode(code)
75+
}
76+
5977
function createConfig(packageName) {
6078
const homeDir = os.homedir()
6179
const configDir = path.join(homeDir, '.config', 'manicode')
@@ -489,7 +507,9 @@ async function checkForUpdates(runningProcess, exitListener) {
489507
const newChild = spawnInstalledBinary({ detached: false })
490508

491509
newChild.on('exit', (code, signal) => {
492-
resetTerminal({ exitAlternateScreen: Boolean(signal) })
510+
resetTerminal({
511+
exitAlternateScreen: shouldExitAlternateScreen(code, signal),
512+
})
493513
printCrashDiagnostics(code, signal)
494514
process.exit(signal ? 1 : (code || 0))
495515
})
@@ -503,7 +523,7 @@ async function checkForUpdates(runningProcess, exitListener) {
503523

504524
function printCrashDiagnostics(code, signal) {
505525
// Windows NTSTATUS codes (unsigned DWORD)
506-
const unsignedCode = code != null && code < 0 ? (code >>> 0) : code
526+
const unsignedCode = getUnsignedExitCode(code)
507527
const isIllegalInstruction =
508528
signal === 'SIGILL' ||
509529
(process.platform === 'win32' && unsignedCode === 0xC000001D)
@@ -621,7 +641,9 @@ async function main() {
621641
const child = spawnInstalledBinary()
622642

623643
const exitListener = (code, signal) => {
624-
resetTerminal({ exitAlternateScreen: Boolean(signal) })
644+
resetTerminal({
645+
exitAlternateScreen: shouldExitAlternateScreen(code, signal),
646+
})
625647
printCrashDiagnostics(code, signal)
626648
process.exit(signal ? 1 : (code || 0))
627649
}

0 commit comments

Comments
 (0)