Unary call throws "Cannot read properties of undefined (reading 'interceptors')"
Problem description
When making unary call and passing metadata as undefined, the library throws:
TypeError: Cannot read properties of undefined (reading 'interceptors')
This error doesn't happen when metadata is provided.
Reproduction steps
The client code when generated using ts-proto and configuring it with --ts_proto_opt=addGrpcMetadata=true, the following is generated:
echo(request: EchoRequest, metadata?: Metadata): Observable<EchoResponse> {
return this.client.echo(request, metadata);
}
When code above is executed without passing a metadata, the TypeError is always thrown if the grpc call is of type UNARY.
Additional context
I managed to track the issue down to InterceptorArguments:
const interceptorArgs: InterceptorArguments = {
clientInterceptors: this[INTERCEPTOR_SYMBOL],
clientInterceptorProviders: this[INTERCEPTOR_PROVIDER_SYMBOL],
callInterceptors: callProperties.callOptions.interceptors ?? [],
callInterceptorProviders:
callProperties.callOptions.interceptor_providers ?? [],
};
The setting of callInterceptors assume that callProperties.callOptions is never undefined. The fix could be made at checkOptionalUnaryResponseArguments L:214:
return { metadata: new Metadata(), options: arg1 || {}, callback: arg2 };
Maybe worth to check also fix L:226:
return { metadata: arg1, options: arg2 || {}, callback: arg3 };
You are required to pass a callback when calling a unary method. The error messaging for that could be better.