Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing exception in the generated code #126

Open
mailsmail opened this issue Sep 7, 2023 · 1 comment
Open

Missing exception in the generated code #126

mailsmail opened this issue Sep 7, 2023 · 1 comment

Comments

@mailsmail
Copy link

mailsmail commented Sep 7, 2023

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

@HeyJavaBean
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants