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
110
Виталий Левченко – 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
Amazon Bedrock Knowledge Bases Hands-on
konny0311
0
150
予防に勝る防御なし(2025年版) - 堅牢なコードを導く様々な設計のヒント / Growing Reliable Code PHP Conference Fukuoka 2025
twada
PRO
39
13k
PHPライセンス変更の議論を通じて学ぶOSSライセンスの基礎
matsuo_atsushi
0
170
Java_プロセスのメモリ監視の落とし穴_NMT_で見抜けない_glibc_キャッシュ問題_.pdf
ntt_dsol_java
0
220
ソフトウェア設計の課題・原則・実践技法
masuda220
PRO
20
11k
Vueで学ぶデータ構造入門 リンクリストとキューでリアクティビティを捉える / Vue Data Structures: Linked Lists and Queues for Reactivity
konkarin
1
310
GeistFabrik and AI-augmented software development
adewale
PRO
0
110
OSS開発者の憂鬱
yusukebe
12
4.9k
AIと協働し、イベントソーシングとアクターモデルで作る後悔しないアーキテクチャ Regret-Free Architecture with AI, Event Sourcing, and Actors
tomohisa
2
5.1k
2026年向け会社紹介資料
misu
0
250
TypeScript 5.9で使えるようになった import defer でパフォーマンス最適化を実現する
bicstone
1
110
DartASTとその活用
sotaatos
2
140
Featured
See All Featured
Speed Design
sergeychernyshev
32
1.2k
How to Think Like a Performance Engineer
csswizardry
28
2.3k
Balancing Empowerment & Direction
lara
5
760
Become a Pro
speakerdeck
PRO
29
5.6k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
132
19k
Statistics for Hackers
jakevdp
799
220k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
Code Reviewing Like a Champion
maltzj
527
40k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
37
2.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
Faster Mobile Websites
deanohume
310
31k
Why Our Code Smells
bkeepers
PRO
340
57k
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
Спасибо!