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

fix typo #24

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/awesome/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ func main () {
## Error需要wrap
GO1.13支持了error wrap。我们可以在错误以下方法,将原始错误进行包装。fmt.Errorf里是%w
```
err = fmt.Errorf("wrap error %w",err)
err = fmt.Errorf("wrap error %w", err)
```
这里需要提醒一点,go官方的error wrap没有堆栈信息,还是比较坑爹

## Error需要IS
以往我们对错误判断都是=,但是如果使用了wrap,在用=是无法相等的:
```
selectErr := fmt.Errorf("select info err: %w",gorm.IsNotRecord)
fmt.Println(selectErr,gorm.IsNotRecord) // false
fmt.Println(errors.Is(selectErr,gorm.IsNotRecord)) // true
selectErr := fmt.Errorf("select info err: %w", gorm.IsNotRecord)
fmt.Println(selectErr == gorm.IsNotRecord) // false
fmt.Println(errors.Is(selectErr, gorm.IsNotRecord)) // true
```

## Error需要收敛
Expand All @@ -55,4 +55,4 @@ fmt.Println(errors.Is(selectErr,gorm.IsNotRecord)) // true

# 引用文献
* [常量error](https://dave.cheney.net/2016/04/07/constant-errors)
* [1.13 Error Wrap深度分析](https://www.cnblogs.com/sunsky303/p/11571440.html)
* [1.13 Error Wrap深度分析](https://www.cnblogs.com/sunsky303/p/11571440.html)