Skip to content

Commit

Permalink
change wrapping error to 错误封装
Browse files Browse the repository at this point in the history
  • Loading branch information
chaoyuepan committed Apr 29, 2024
1 parent ef695a9 commit 082ab0c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/008.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Tip #8 包裹错误
# Tip #8 错误封装

> 原始链接:[Golang Tip #8: Wrapping Errors](https://twitter.com/func25/status/1729768084100300945)
>
通常,我们会使用`fmt.Errorf``%w`把一个错误包裹到另外一个错误里,像这样:
通常,我们会使用`fmt.Errorf``%w`把一个错误封装到另外一个错误里,像这样:

![](./images/008/008_01.png)

但是在Go 1.20,我们有一个更直接和友好的方法去包裹错误,那就是使用`errors.Join()`
但是在Go 1.20,我们有一个更直接和友好的方法去错误封装,那就是使用`errors.Join()`

![](./images/008/008_02.jpg)
2 changes: 1 addition & 1 deletion src/014.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

**为什么要小写?**

错误信息经常会被包裹或者合并到其他错误信息里
错误信息经常会被封装或者合并到其他错误信息里

如果一条错误信息以大写字母开头,那么当它出现在句子中间的时候,看起来就会很怪或者显得格格不入。

Expand Down
2 changes: 1 addition & 1 deletion src/066.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

(感谢 `@thedenisnikulin` 提供的额外建议,我们可以进一步改进错误处理方式。)

现在,我们应该熟悉使用 `fmt.Errorf` 函数以及 `%w` 来包裹(wrap)错误的做法:
现在,我们应该熟悉使用 `fmt.Errorf` 函数以及 `%w` 来封装(wrap)错误的做法:

![](./images/066/1.png)

Expand Down
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [Tip #5 方法链](./005.md)
- [Tip #6 下划线导入](./006.md)
- [Tip #7 本tip已删除](./007.md)
- [Tip #8 包裹错误](./008.md)
- [Tip #8 错误封装](./008.md)
- [Tip #9 编译时接口检查](./009.md)
- [Tip #10 避免裸露参数](./010.md)
- [Tip #11 数字分隔符](./011.md)
Expand Down

0 comments on commit 082ab0c

Please sign in to comment.