From 91f452fcfe2f3e6cd323b1ef0da24334fee2a812 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1aki=20Baz=20Castillo?= Date: Fri, 5 Jan 2024 11:59:20 +0100 Subject: [PATCH] logs in Channel.ts --- node/src/Channel.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/node/src/Channel.ts b/node/src/Channel.ts index 7f41ca9f2f1..48e2f88cf28 100644 --- a/node/src/Channel.ts +++ b/node/src/Channel.ts @@ -177,7 +177,8 @@ export class Channel extends EnhancedEventEmitter { logger.error( 'received invalid message from the worker process: %s', - String(error)); + String(error) + ); } } @@ -266,7 +267,9 @@ export class Channel extends EnhancedEventEmitter if (this.#closed) { - throw new InvalidStateError('Channel closed'); + throw new InvalidStateError( + `Channel closed, cannot send notification [event:${Event[event]}]` + ); } const handlerIdOffset = this.#bufferBuilder.createString(handlerId); @@ -302,7 +305,7 @@ export class Channel extends EnhancedEventEmitter if (buffer.byteLength > MESSAGE_MAX_LEN) { - throw new Error('Channel request too big'); + throw new Error(`notification too big [event:${Event[event]}]`); } try @@ -326,9 +329,13 @@ export class Channel extends EnhancedEventEmitter { if (this.#closed) { - throw new InvalidStateError('Channel closed'); + throw new InvalidStateError( + `Channel closed, cannot send request [method:${Method[method]}]` + ); } + logger.debug('request() [method:%s]', Method[method]); + this.#nextId < 4294967295 ? ++this.#nextId : (this.#nextId = 1); const id = this.#nextId; @@ -366,7 +373,7 @@ export class Channel extends EnhancedEventEmitter if (buffer.byteLength > MESSAGE_MAX_LEN) { - throw new Error('Channel request too big'); + throw new Error(`request too big [method:${Method[method]}]`); } // This may throw if closed or remote side ended. @@ -398,7 +405,9 @@ export class Channel extends EnhancedEventEmitter }, close : () => { - pReject(new InvalidStateError('Channel closed')); + pReject(new InvalidStateError( + `Channel closed, pending request aborted [method:${Method[method]}, id:${id}]` + )); } }; @@ -451,7 +460,8 @@ export class Channel extends EnhancedEventEmitter { logger.error( 'received response is not accepted nor rejected [method:%s, id:%s]', - sent.method, sent.id); + sent.method, sent.id + ); } }