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

gerror.NewCode has different returns in different gf versions #3699

Closed
xiaoxintiaoda opened this issue Jul 22, 2024 · 7 comments · Fixed by #3640
Closed

gerror.NewCode has different returns in different gf versions #3699

xiaoxintiaoda opened this issue Jul 22, 2024 · 7 comments · Fixed by #3640
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@xiaoxintiaoda
Copy link

Go version

go version go1.22.0 darwin/arm64

GoFrame version

2.7.2

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

# 2.7.0
var err1 = gerror.NewCode(gcode.New(1000, "测试", nil), "测试")
var err2 = gerror.NewCode(gcode.New(1000, "测试", nil), "测试")
fmt.Println(errors.Is(err1, err2)) // return true
# 2.7.2
var err1 = gerror.NewCode(gcode.New(1000, "测试", nil), "测试")
var err2 = gerror.NewCode(gcode.New(1000, "测试", nil), "测试")
fmt.Println(errors.Is(err1, err2)) // return false

What did you see happen?

在2.7.0版本和2.7.2版本表现有差异

What did you expect to see?

在2.7.0版本和2.7.2版本应该都返回true

@xiaoxintiaoda xiaoxintiaoda added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jul 22, 2024
@shuqingzai
Copy link

See: #3640

@xiaoxintiaoda
Copy link
Author

xiaoxintiaoda commented Jul 23, 2024

不好意思,那我想咨询一下,以下结果对你们来说是预期内的吗,因为我们之前使用2.7.0和2.7.1版本,有一些就是使用的这种错误判断,判断结果都是true。但是使用的后续2.7.2,判断结果都是false,那可能我需要做一些修改

# 2.7.2
var err1 = gerror.NewCode(gcode.New(1000, "测试", nil), "测试")
var err2 = gerror.NewCode(gcode.New(1000, "测试", nil), "测试")
fmt.Println(errors.Is(err1, err2)) // return false

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Sorry, I would like to ask. The following results are expected, because we used version 2.7.0 before, and some of them used this kind of wrong judgment, and the judgment results were all true. If the judgment results are false in subsequent 2.7.2 and later versions, then I may need to make some modifications.

# 2.7.2
var err1 = gerror.NewCode(gcode.New(1000, "test", nil), "test")
var err2 = gerror.NewCode(gcode.New(1000, "test", nil), "test")
fmt.Println(errors.Is(err1, err2)) // return false

@xiaoxintiaoda
Copy link
Author

See: #3640

我看了这个pr,但是pr内容是修改的gerror.Is 方法,我是直接使用的errors.Is方法判断的

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


See: #3640

I read this pr, but the pr content is the modified gerror.Is method. I directly use the errors.Is method to judge.

@shuqingzai
Copy link

See: #3640

我看了这个pr,但是pr内容是修改的gerror.Is 方法,我是直接使用的errors.Is方法判断的

从逻辑上来说,是符合预期,因为你初始化 gerror 时,gerror.Error.error == nil ,在标准库中,使用 errors.Is 且实现 Unwrap ,返回 nil 就会判定为 false

See:

return err.error

如果两个 code 完全一致,你应该可以尝试使用 gerror.HasCode

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


See: #3640

I read this pr, but the pr content is the modified gerror.Is method. I directly use the errors.Is method to judge.

Logically speaking, it is in line with expectations, because when you initialize gerror, gerror.Error.error == nil, in the standard library, use errors.Is and implement Unwrap, returning nil will be judged as false

See:

return err.error

If the two codes are exactly the same, you should try using gerror.HasCode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants