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

使用错误码创建的error,打印不出错误信息 #3

Open
xuefengyuan opened this issue Jul 5, 2022 · 1 comment
Open

使用错误码创建的error,打印不出错误信息 #3

xuefengyuan opened this issue Jul 5, 2022 · 1 comment

Comments

@xuefengyuan
Copy link

func (u *userRepo)Info(ctx context.Context) error { return errors.WithCode(code.ErrDatabase, "data 层 user info 操作失败%s","test") }

fmt.Println(fmt.Sprintf("== == %s", err))
输出的日志是空的

@cyb0225
Copy link

cyb0225 commented Oct 9, 2022

func (u *userRepo)Info(ctx context.Context) error { return errors.WithCode(code.ErrDatabase, "data 层 user info 操作失败%s","test") }

fmt.Println(fmt.Sprintf("== == %s", err)) 输出的日志是空的
因为你用的是%s打印,他会默认调用err的Error函数,所以打印出来的不是你上面“"data 层 user info 操作失败%s","test"”这段内容,应该是你”code.ErrDatabase“,注册的msg内容,你可以检查一下这块有没有问题。

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

2 participants