Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Виталий Левченко – Go 2: ошибки, их логирование...
Search
GolangMoscow
August 29, 2019
Programming
0
100
Виталий Левченко – Go 2: ошибки, их логирование, и как нам с этим жить
GolangMoscow
August 29, 2019
Tweet
Share
More Decks by GolangMoscow
See All by GolangMoscow
Антон Кильчик – Дженерики, которые мы заслужили
golangmoscow
0
540
Yegor Myskin – HOW WE MAKE GRPC
golangmoscow
0
120
Other Decks in Programming
See All in Programming
AIと”コードの評価関数”を共有する / Share the "code evaluation function" with AI
euglena1215
1
180
MDN Web Docs に日本語翻訳でコントリビュートしたくなる
ohmori_yusuke
1
130
Rails Frontend Evolution: It Was a Setup All Along
skryukov
0
280
レベル1の開発生産性向上に取り組む − 日々の作業の効率化・自動化を通じた改善活動
kesoji
1
300
Android 16KBページサイズ対応をはじめからていねいに
mine2424
0
460
Git Sync を超える!OSS で実現する CDK Pull 型デプロイ / Deploying CDK with PipeCD in Pull-style
tkikuc
4
360
ペアプロ × 生成AI 現場での実践と課題について / generative-ai-in-pair-programming
codmoninc
2
22k
PipeCDのプラグイン化で目指すところ
warashi
1
310
顧客の画像データをテラバイト単位で配信する 画像サーバを WebP にした際に起こった課題と その対応策 ~継続的な取り組みを添えて~
takutakahashi
4
1.3k
効率的な開発手段として VRTを活用する
ishkawa
1
170
A full stack side project webapp all in Kotlin (KotlinConf 2025)
dankim
0
150
リバースエンジニアリング新時代へ! GhidraとClaude DesktopをMCPで繋ぐ/findy202507
tkmru
3
1k
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
RailsConf 2023
tenderlove
30
1.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
50
5.5k
Optimizing for Happiness
mojombo
379
70k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
181
54k
Stop Working from a Prison Cell
hatefulcrawdad
271
21k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
What's in a price? How to price your products and services
michaelherold
246
12k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
5.9k
GraphQLとの向き合い方2022年版
quramy
49
14k
Transcript
Go 2: ошибки, их логирование, и как нам с этим
жить Виталий Левченко
Обо мне • 11 лет в индустрии • Go разработчик
с 2012 • Тимлид • CTO • Product owner @ Uteka • Лидер Go, SRE, Teamlead сообществ Петербурга
GO SPB t.me/goleningrad
None
None
None
Go 2 • https://go.googlesource.com/proposal/+/master/design/ go2draft-error-printing.md • https://go.googlesource.com/proposal/+/master/design/ 32437-try-builtin.md • https://go.googlesource.com/proposal/+/master/design/
go2draft-error-inspection.md • https://go.googlesource.com/proposal/+/master/design/ go2draft-error-handling-overview.md • https://go.googlesource.com/proposal/+/master/design/ go2draft-error-handling.md
Постановка задачи
Постановка задачи • Avoid return
Постановка задачи • Avoid return • Log error
Постановка задачи • Avoid return • Log error • Debug
error
Постановка задачи • Avoid return • Log error • Debug
error • Log trace
Постановка задачи • Avoid return • Log error • Debug
error • Log trace • Handle error
Постановка задачи • Avoid return • Log error • Debug
error • Log trace • Handle error • Create error
Try / handle
Try / handle func() { defer fmt.HandleErrorf(&err, “open file %s",
path) file := try(os.Open(path)) defer file.Close() }
Try / handle func() { defer fmt.HandleErrorf(&err, “open file %s",
path) file := try(os.Open(path)) defer file.Close() } Abandoned
Постановка задачи • Avoid return (ждём нового try) • Log
error • Debug error • Log trace • Handle error • Create error
Log error type Formatter interface { Format(p Printer) (next error)
} type Printer interface { Print(args ...interface{}) Printf(format string, args ...interface{}) Detail() bool }
Log error type Formatter interface { Format(p Printer) (next error)
} type Printer interface { Print(args ...interface{}) Printf(format string, args ...interface{}) Detail() bool } Abandoned
Log error • https://godoc.org/golang.org/x/xerrors • https://tip.golang.org/pkg/fmt/#Errorf • https://github.com/joomcode/errorx
Log error interface { Unwrap() error }
Log error err := fmt.Errorf("file open err: %w", err)
Log error • Add fields: []zap.Field or whatever
Log error
Постановка задачи • Avoid return (ждём нового try) • Log
error (use xerror and wait for go1.13) • Debug error • Log trace • Handle error • Create error
Постановка задачи • Avoid return (ждём нового try) • Log
error (use xerror and wait for go1.13) • Debug error (use explicitly) • Log trace • Handle error • Create error
Log errors
Log trace • https://github.com/pkg/errors • https://github.com/go-errors/errors • Etc…
Log trace • https://github.com/pkg/errors • https://github.com/go-errors/errors • Etc… • Or
custom
Log trace • https://github.com/pkg/errors • https://github.com/go-errors/errors • Etc… • Or
custom • Send to sentry or whatever
Log trace
Постановка задачи • Avoid return (ждём нового try) • Log
error (use xerror and wait for go1.13) • Debug error (use explicitly) • Log trace (custom wrappers) • Handle error • Create error
Handle error • https://godoc.org/golang.org/x/xerrors • https://tip.golang.org/pkg/fmt/#Errorf
Handle error if errors.Is(err, os.ErrExist) { ... }
Handle error if errors.Is(err, os.ErrExist) { ... } var perr
*os.PathError if errors.As(err, &perr) { fmt.Println(perr.Path) }
Handle error
Постановка задачи • Avoid return (ждём нового try) • Log
error (use xerror and wait for go1.13) • Debug error (use explicitly) • Log trace (custom wrappers and pain) • Handle error (use xerror and wait for go1.13) • Create error
Постановка задачи • Avoid return • Log error (lib +
custom wrapper) • Debug error (custom) • Log trace (libs and custom) • Handle error (custom) • Create error (custom)
Постановка задачи • Avoid return (or custom panics) • Log
error (lib + custom wrapper) • Debug error (custom) • Log trace (libs and custom) • Handle error (custom) • Create error (custom)
Обработка ошибок в Go
Custom error type Custom struct { message string error error
stack xerrors.Frame type string fields []zap.Field }
Custom error func New(e error, msg, type string, fields []zap.Field)
error interface { Error() string Is(error) bool Unwrap() error AddFields([]zap.Field) Custom EncodeError() []byte }
Custom error type Custom struct { message string error error
stack xerrors.Frame type string fields []zap.Field } Or use: • https://github.com/joomcode/errorx
Official • https://github.com/golang/go/wiki/ Go2ErrorValuesFeedback • https://github.com/golang/go/wiki/ Go2ErrorHandlingFeedback • https://blog.golang.org/experiment
Official • https://github.com/golang/go/wiki/ Go2ErrorValuesFeedback • https://github.com/golang/go/wiki/ Go2ErrorHandlingFeedback • https://blog.golang.org/experiment
Спасибо!