Skip to content

Commit a4648ea

Browse files
authored
fix: log uncaughtException errors directly to stderr (#612)
when server is exiting unexpectedly, there is no guarantee that console.log will propagate back to LSP client
1 parent 45e999a commit a4648ea

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

runtimes/runtimes/standalone.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ import { makeProxyConfigv2Standalone, makeProxyConfigv3Standalone } from './util
8686
import { newAgent } from './agent'
8787
import { ShowSaveFileDialogRequestType } from '../protocol/window'
8888
import { getTelemetryReasonDesc } from './util/shared'
89+
import { writeSync } from 'fs'
90+
import { format } from 'util'
8991

9092
// Honor shared aws config file
9193
if (checkAWSConfigFile()) {
@@ -105,7 +107,10 @@ function setupCrashMonitoring(telemetryEmitter?: (metric: MetricEvent) => void)
105107
}
106108

107109
process.on('uncaughtExceptionMonitor', (err, origin) => {
110+
// also emit to stderr in case stdout does not completely drain
111+
// console error is monkey-patched by vscode-languageserver in stdio mode to log to client instead of stderr
108112
console.error('Uncaught Exception:', err.message, getTopStackFrames(err))
113+
writeSync(process.stderr.fd, `Uncaught exception: ${format(err)}\n` + `Exception origin: ${origin}\n`)
109114

110115
if (telemetryEmitter) {
111116
try {

0 commit comments

Comments
 (0)