errors icon indicating copy to clipboard operation
errors copied to clipboard

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

Open xuefengyuan opened this issue 2 years ago • 1 comments

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

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

xuefengyuan avatar Jul 05 '22 14:07 xuefengyuan

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内容,你可以检查一下这块有没有问题。

cyb0225 avatar Oct 09 '22 13:10 cyb0225