Closed arjca closed 3 months ago
I investigated a bit and found something odd.
In the function GetOperationInfo
of file rules/internal/utils/extension.go
, there is a check for nil value at line 47. If the value is not nil, it is then cast as a pointer to lrpb.OperationInfo
. However, after the cast, value is now nil!
See:
opts := m.GetMethodOptions()
if x := proto.GetExtension(opts, lrpb.E_OperationInfo); x != nil {
fmt.Println(x == nil) // => false
fmt.Println(x.(*lrpb.OperationInfo) == nil) // => true (!)
return x.(*lrpb.OperationInfo)
}
I got this case because I did not put the option operation_info
in my method. I then modified my example:
syntax = "proto3";
package arjca.prj.v1;
import "google/api/annotations.proto";
import "google/longrunning/operations.proto";
service AwesomeService {
rpc Process(ProcessRequest) returns (google.longrunning.Operation) {
option (google.longrunning.operation_info) = {
response_type: "ProcessResponse"
};
};
}
message ProcessRequest {
}
message ProcessResponse {
}
And it works!
Still, I think that the behavior with the missing google.longrunning.operation_info
option is not desired. The error message should be more compelling, so that users understand what they have to modify. Or perhaps the linter should not crash at all, as the absence of this option should be covered by AIP-151.
Hi,
One method of my Protobuf service is expected to return early, and proceed to computations after the response. Google Cloud guidelines say this method must return a
google.longrunning.Operation
.When following this rule,
api-linter
returns an error:runtime error: invalid memory address or nil pointer dereference
. There is no error if I replacegoogle.longrunning.Operation
bygoogle.protobuf.Empty
, for instance.Stack trace with
--debug
is the following:The error is produced in rule AIP-136 when using a method from
utils
: usingGetResponseType
on thedesc.MethodDescriptor
of the method returninggoogle.longrunning.Operation
returnsnil
.Environment details
Arch Linux x86_64
go1.22.4 linux/amd64
1.66.1
Steps to reproduce
api-linter
returns the error with the following code:I uploaded a repository with this code and dependencies (
googleapis
Protobuf files): https://github.com/arjca/api-linter-bug-longrunning. To reproduce: clone it, fetch the submodule (make init
) and finally runapi-linter
(make lint
).