Skip to content

Commit bfed3f1

Browse files
author
Benjamin E. Coe
authored
feat(debug): capture stack trace in errors rather than message (#718)
1 parent b940811 commit bfed3f1

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,10 @@ export {
143143
Topic,
144144
TopicMetadata,
145145
} from './topic';
146+
147+
if (process.env.DEBUG_GRPC) {
148+
console.info('gRPC logging set to verbose');
149+
const {setLogger, setLogVerbosity, logVerbosity} = require('@grpc/grpc-js');
150+
setLogger(console);
151+
setLogVerbosity(logVerbosity.DEBUG);
152+
}

src/message-queues.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ export class BatchError extends Error implements ServiceError {
4343
metadata: Metadata;
4444
constructor(err: ServiceError, ackIds: string[], rpc: string) {
4545
super(
46-
`Failed to "${rpc}" for ${ackIds.length} message(s). Reason: ${err.message}`
46+
`Failed to "${rpc}" for ${ackIds.length} message(s). Reason: ${
47+
process.env.DEBUG_GRPC ? err.stack : err.message
48+
}`
4749
);
4850

4951
this.ackIds = ackIds;

src/message-stream.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,11 @@ export class ChannelError extends Error implements ServiceError {
9292
details: string;
9393
metadata: Metadata;
9494
constructor(err: Error) {
95-
super(`Failed to connect to channel. Reason: ${err.message}`);
95+
super(
96+
`Failed to connect to channel. Reason: ${
97+
process.env.DEBUG_GRPC ? err.stack : err.message
98+
}`
99+
);
96100
this.code = err.message.includes('deadline')
97101
? status.DEADLINE_EXCEEDED
98102
: status.UNKNOWN;

0 commit comments

Comments
 (0)