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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
MDN Web Docs に日本語翻訳でコントリビュート
ohmori_yusuke
0
660
Gemini for developers
meteatamel
0
100
AI Agent の開発と運用を支える Durable Execution #AgentsInProd
izumin5210
7
2.3k
AI & Enginnering
codelynx
0
120
なぜSQLはAIぽく見えるのか/why does SQL look AI like
florets1
0
480
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
CSC307 Lecture 05
javiergs
PRO
0
500
AIで開発はどれくらい加速したのか?AIエージェントによるコード生成を、現場の評価と研究開発の評価の両面からdeep diveしてみる
daisuketakeda
1
2.5k
それ、本当に安全? ファイルアップロードで見落としがちなセキュリティリスクと対策
penpeen
7
4k
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
Oxlint JS plugins
kazupon
1
1k
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
3
220
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Between Models and Reality
mayunak
1
200
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.6k
AI: The stuff that nobody shows you
jnunemaker
PRO
2
280
Done Done
chrislema
186
16k
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
160
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
200
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
The agentic SEO stack - context over prompts
schlessera
0
650
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
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
Спасибо!