Learning go error handling design from open source - Yu-Lang Chu

tags: COSCUP2021 Skilled zh-tw COSCUP2021 From Beginner to Gopher TR209

歡迎來到 https://hackmd.io/@coscup/2021 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

請從這裡開始

Go Error API

Survive under the Crap Go Error System

Error are values

"Values can be programmed, and since errors are values, errors can be programmed." Rob Pike

  • Strucct internal error
  • Error check inside function variable

Error handling strategies

Three categories of errors

Sentinel Error

  • predefined value

Error type

  • with more information
  • e.g. URL, email

Opaque error

  • asser errors for hehaviour not type
  • only care True/ False, but not error struct

Error Handling design in open source project

  • TiKV
    • Error type
    • Opaque error
  • go-redis
    • Opaque error
  • Prometheus TSDB
  • K8s APImachinery
  • Go-Kratos
Select a repo