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

函数返回值和错误信息只能二选一? #238

Closed
bugmeooo opened this issue Aug 21, 2020 · 4 comments
Closed

函数返回值和错误信息只能二选一? #238

bugmeooo opened this issue Aug 21, 2020 · 4 comments

Comments

@bugmeooo
Copy link

`
func (imp *HelloImp) Test() (int32, error) {
//这样客户端可以获得 返回值 -1 和 nil
return -1, nil
}

func (imp *HelloImp) Test() (int32, error) {
//这样客户端只能获得 返回值 0 和 “test error”
return -1, errors.New("test error")
}
`
当服务端函数返回值 error存在时,第一个返回值信息就不会返回!
这个问题怎么解?

@hbinr
Copy link

hbinr commented Aug 24, 2020

刚刚测试了,没有任何问题。和框架没关系,可能是你的go代码写的有问题。。断点调试下

@bugmeooo
Copy link
Author

刚刚测试了,没有任何问题。和框架没关系,可能是你的go代码写的有问题。。断点调试下

我的环境是:TarsFramework >= v2.4.4, TarsGo >= v1.1.4
协议:
int Test(int x);

实现代码:
func (imp *EthereumWalletImp) Test(ctx context.Context, t int32) (int32, error) { //Doing something in your function //... if t > 10 { return t, errors.New("What?") } return t, nil }
通过后台提供的在线接口调试:
参数为:
-13
结果:
{"consttime":0.7267720103263855,"arguments":{},"return":-13}

参数为:
20
结果:
{"costtime":2.1954140663146973,"error":{"code":1,"message":"What?"}}

确实是 存在 error时,另外一个参数不返回
不管是我客户端代码 还是 官方的后台 接口调试 返回都是这样

@tarscloudbot
Copy link
Contributor

该issue长期未更新。如果问题依旧没解决,欢迎重新打开issue。TARS社区有您更精彩。

Thanks for your supporting. The issue has not been updated for a long time. If the problem is still not resolved, welcome to reopen the issue.

@MeiJunh
Copy link

MeiJunh commented Apr 15, 2021

刚刚测试了,没有任何问题。和框架没关系,可能是你的go代码写的有问题。。断点调试下

这个应该是自动生成代码中的逻辑。
我新建了一个pb,然后构建,其中自动生成的Dispatch函数中会在function返回err时直接返回err而没有将rsp塞回至output。可能是使用方式不一样导致会有一些误解。

如下图,当函数返回err则dispatch直接返回了

image

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

No branches or pull requests

4 participants