Skip to content
This repository was archived by the owner on Nov 6, 2018. It is now read-only.

Commit 1f34d21

Browse files
committed
fix: propagate stack traces
1 parent a073382 commit 1f34d21

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/protocol/jsonrpc2/connection.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ describe('Connection', () => {
7676
(error: ResponseError<any>) => {
7777
assert.strictEqual(error.code, ErrorCodes.InternalError)
7878
assert.strictEqual(error.message, 'test')
79+
assert.strictEqual(error.data && typeof error.data.stack, 'string')
7980
}
8081
)
8182
})
@@ -95,6 +96,7 @@ describe('Connection', () => {
9596
(error: ResponseError<any>) => {
9697
assert.strictEqual(error.code, ErrorCodes.InternalError)
9798
assert.strictEqual(error.message, 'test')
99+
assert.strictEqual(error.data && typeof error.data.stack, 'string')
98100
}
99101
)
100102
})

src/protocol/jsonrpc2/connection.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ function _createConnection(transports: MessageTransports, logger: Logger, strate
365365
if (error instanceof ResponseError) {
366366
replyError(error as ResponseError<any>)
367367
} else if (error && typeof error.message === 'string') {
368-
replyError(new ResponseError<void>(ErrorCodes.InternalError, error.message))
368+
replyError(
369+
new ResponseError<void>(ErrorCodes.InternalError, error.message, {
370+
stack: error.stack,
371+
...error,
372+
})
373+
)
369374
} else {
370375
replyError(
371376
new ResponseError<void>(
@@ -387,7 +392,12 @@ function _createConnection(transports: MessageTransports, logger: Logger, strate
387392
if (error instanceof ResponseError) {
388393
reply(error as ResponseError<any>)
389394
} else if (error && typeof error.message === 'string') {
390-
replyError(new ResponseError<void>(ErrorCodes.InternalError, error.message))
395+
replyError(
396+
new ResponseError<void>(ErrorCodes.InternalError, error.message, {
397+
stack: error.stack,
398+
...error,
399+
})
400+
)
391401
} else {
392402
replyError(
393403
new ResponseError<void>(

0 commit comments

Comments
 (0)