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
550
Yegor Myskin – HOW WE MAKE GRPC
golangmoscow
0
120
Other Decks in Programming
See All in Programming
ZJIT: The Ruby 4 JIT Compiler / Ruby Release 30th Anniversary Party
k0kubun
1
320
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
690
Combinatorial Interview Problems with Backtracking Solutions - From Imperative Procedural Programming to Declarative Functional Programming - Part 2
philipschwarz
PRO
0
140
QAフローを最適化し、品質水準を満たしながらリリースまでの期間を最短化する #RSGT2026
shibayu36
0
1.8k
大規模Cloud Native環境におけるFalcoの運用
owlinux1000
0
250
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
180
実は歴史的なアップデートだと思う AWS Interconnect - multicloud
maroon1st
0
310
TestingOsaka6_Ozono
o3
0
270
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
1.2k
Navigation 3: 적응형 UI를 위한 앱 탐색
fornewid
1
540
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
2
790
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
630
Featured
See All Featured
End of SEO as We Know It (SMX Advanced Version)
ipullrank
2
3.9k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
270
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.3k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.3k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
130
My Coaching Mixtape
mlcsv
0
23
Crafting Experiences
bethany
0
28
What's in a price? How to price your products and services
michaelherold
246
13k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.5k
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
Спасибо!