From b5e35c2711f9b4641dbcb62a93fcde3f44441475 Mon Sep 17 00:00:00 2001 From: Devesh Kumar Date: Mon, 3 Nov 2025 10:05:19 +0530 Subject: [PATCH 1/2] v1 reflection: Bail out early for required configs not passed --- src/client.ts | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/client.ts b/src/client.ts index eb10bf9..e60ca57 100644 --- a/src/client.ts +++ b/src/client.ts @@ -57,6 +57,10 @@ export class Client { options?: object, metadata?: Metadata ) { + if (!url) { + throw new Error('Error: url is required for server reflection'); + } + this.url = url; this.credentials = credentials; this.clientOptions = options; @@ -114,27 +118,27 @@ export class Client { supportedReflectionAPIVersions[ version as keyof typeof supportedReflectionAPIVersions ]; - const { - service: servicePromise, - client: clientPromise, - } = protocolConfig; - - const [protocolService, protocolClient] = await Promise.all([ - servicePromise, - clientPromise, - ]); - - const grpcClientForProtocol = new protocolService.ServerReflectionClient( - this.url, - this.credentials, - this.clientOptions - ); - const request = new protocolClient.ServerReflectionRequest(); + try { + const {service: servicePromise, client: clientPromise} = + protocolConfig; + + const [protocolService, protocolClient] = await Promise.all([ + servicePromise, + clientPromise, + ]); + + const grpcClientForProtocol = + new protocolService.ServerReflectionClient( + this.url, + this.credentials, + this.clientOptions + ); - request.setListServices('*'); + const request = new protocolClient.ServerReflectionRequest(); + + request.setListServices('*'); - try { const [reflectionResponse] = await this.sendReflectionRequest( request, grpcClientForProtocol @@ -174,7 +178,7 @@ export class Client { }); const resultWithServiceError = evaluationResults.find(res => { - // Something is actually wrong with the gRPC service + // Something is actually wrong with the gRPC service or client return res.error && res.error.code !== GrpcStatus.UNIMPLEMENTED; }); From a83817ce09db5cf258d0ce5c8fd63ec44d94d2c8 Mon Sep 17 00:00:00 2001 From: Devesh Kumar Date: Mon, 3 Nov 2025 10:08:08 +0530 Subject: [PATCH 2/2] Add check for credentials to be passed in gRPC Client constructor --- src/client.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/client.ts b/src/client.ts index e60ca57..e60d273 100644 --- a/src/client.ts +++ b/src/client.ts @@ -61,6 +61,12 @@ export class Client { throw new Error('Error: url is required for server reflection'); } + if (!credentials) { + throw new Error( + 'Error: credentials parameter is required for server reflection' + ); + } + this.url = url; this.credentials = credentials; this.clientOptions = options;