cloudwego/thriftgo

Missing exception in the generated code

mailsmail opened this issue · 1 comments

Hello, I tried to generate a Go code from simple Thrift file and I noticed that there are some difference in the code generated by Apache Thrift and ThriftGo. The code generated by ThriftGo is missing some lines that handle exception. It happen to void function that throw exception.

This is the thrift file:

exception SomeException {
	1: string message
}

service SomeService
{
	void some_function() throws(1:SomeException o1)
}

Then using Apache Thrift (v0.13.0) the generated Go code is:

func (p *SomeServiceClient) SomeFunction(ctx context.Context) (err error) {
	var _args0 SomeServiceSomeFunctionArgs
	var _result1 SomeServiceSomeFunctionResult
	if err = p.Client_().Call(ctx, "some_function", &_args0, &_result1); err != nil {
		return
	}
	switch {
	case _result1.O1 != nil:
		return _result1.O1
	}

	return nil
}

But, when using ThriftGo (v0.3.1) the generated code is:

func (p *SomeServiceClient) SomeFunction(ctx context.Context) (err error) {
	var _args SomeServiceSomeFunctionArgs
	var _result SomeServiceSomeFunctionResult
	if err = p.Client_().Call(ctx, "some_function", &_args, &_result); err != nil {
		return
	}
	return nil
}

As you can see, the switch block that handle the exception is missing.

I'm not familiar with the ThriftGo, but I guess it is because in this template https://github.com/cloudwego/thriftgo/blob/main/generator/golang/templates/client.go#L96-L103 the throw exception will be generated if the function is not a void type.

Thank you

Thanks for catching this issue! Sorry about that, we actually have a little bug in our code implementation. I'll fix this later.