Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しい...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
utagawa kiki
April 28, 2024
Programming
4.4k
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go製Webアプリケーションのエラーとの向き合い方大全、あるいはやっぱりスタックトレース欲しいやん / Kyoto.go #50
Kyoto.go #50 LT
https://kyotogo.connpass.com/event/313309/
utagawa kiki
April 28, 2024
More Decks by utagawa kiki
See All by utagawa kiki
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
2
1.5k
new(1.26) ← これすき / kamakura.go #8
utgwkk
0
4.7k
tparseでgo testの出力を見やすくする
utgwkk
2
2.2k
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
4
2.7k
自動で //nolint を挿入する取り組み / Gopher's Gathering
utgwkk
1
3.4k
ゆるやかにgolangci-lintのルールを強くする / Kyoto.go #56
utgwkk
2
4.6k
君たちはどうコードをレビューする (される) か / 大吉祥寺.pm
utgwkk
21
17k
Dive into gomock / Go Conference 2024
utgwkk
14
8.8k
Goでリフレクションする、その前に / Kansai.go #1
utgwkk
4
3.8k
Other Decks in Programming
See All in Programming
Laravelのアプリケーションをどこにデプロイするか #ツナギメオフライン.9
akase244
0
120
LL言語やWebフレームワークのPostgreSQL対応 〜DBの機能がユーザーに届くまで〜
kentaroutakeda
0
150
業務時間外もAIに働いてもらう話
colorful12
3
10k
ゲームコントローラやキーボードのファームウェアをSwiftで書く
kishikawakatsumi
1
100
tsc.rip を支える技術 / Kyoto.なんか #8
susisu
0
4.4k
不幸な GC
chencmd
0
900
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
2.7k
Go × SIMDで高速化するベクトル検索 ~ルーフラインモデルでSIMDが効く境界を探れ! ~
po3rin
1
200
GraphRAGのKnowledge Graphを 直接!見る/View-GraphRAG's-KnowledgeGraph-directly!
tyumugi1113
1
280
Foundry Localでエージェント開発
seosoft
0
160
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
130
新人はどこまで自力でやり、どこからAIに頼るべきか/エンジニア育成に向き合う_先輩たちの悩みと知見共有会
toppan_digital_dev
1
590
Featured
See All Featured
GraphQLとの向き合い方2022年版
quramy
50
15k
Building Applications with DynamoDB
mza
96
7.2k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2.8k
KATA
mclloyd
PRO
35
15k
Un-Boring Meetings
codingconduct
0
410
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
520
Raft: Consensus for Rubyists
vanstee
141
7.7k
The Curious Case for Waylosing
cassininazir
1
500
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Transcript
Go製Webアプリケーションの エラーとの向き合い方大全 あるいは やっぱりスタックトレース欲しいやん Kyoto.go #50 @utgwkk (うたがわきき)
自己紹介 @utgwkk (うたがわきき) 株式会社はてな Webアプリケーションエンジニア in 京都 最近はGoを書いて暮らしています
ここで宣伝 Go Conference 2024 (6/8) で登壇します Dive into gomockというタイトルでやります 渋谷で会いましょう
まったく関係ない宣伝 アイコンのステッカー配っています
アンケート Goでエラーハンドリングをしたことがある? (ここで挙手を促す)
前提 Go製Webアプリケーション GraphQL API (gqlgen) + REST API
Goのエラーといえば? if err != nil { return nil, err }
return errors.New("not found") return fmt.Errorf("failed to fetch: %w", err)
課題感 return nil, err どこで発生したエラーなのか分からない そうして、向き合いが発生したのであった こうやって向き合っているよ〜という歩みと現状を紹介
fmt.Errorf でラップする return fmt.Errorf("failed to fetch: %w", err) メッセージを都度考える必要がある どこで発生したエラーなのか一意に定まらない
(grepしたらいけるけど)
golang.org/x/xerrors を使う時代 スタックトレース付きでエラーを返せる return xerrors.Errorf("failed to fetch: %w", err) ほぼ非推奨になっているパッケージを使いつづけることへの不安
(Errorfはdeprecated解除された) メッセージを都度考える必要があるのには変わりがない xerrors.Errorf(": %w", err) というイディオムがあるにはあるが
panicを使う……? package main func main() { doSomething() } func doSomething()
{ panic("failed!!") }
panicを使う……? panic: failed!! goroutine 1 [running]: main.doSomething(...) /tmp/sandbox423004243/prog.go:8 main.main() /tmp/sandbox423004243/prog.go:4
+0x25
panicを使う……? panicしたらスタックトレースが載る!! けっこう真面目に考えたこともあったけど却下 Goの標準的なエラーハンドリング方法から大きく外れる どこからエラーが返ってくるのか予測不能になる
オレオレライブラリでスタックトレースを載せる return errwithframe.New(err) xerrorsの実装を真似る Errorメソッドでスタックトレースを出力する いったんこれで落ち着いている 世間にあるライブラリを使ったほうがいいかも? (後述します)
スタックトレースの時代が来ている 各社で事例あり Go言語のAPIサーバーの冗長なエラーログを40%削減した話 #LayerXテック アドカレ - LayerX エンジニアブログ UbieにおけるGo言語のエラーハンドリング
エラーハンドリングへの関心が高まっている https://findy.connpass.com/event/314417/
Goのエラーがスタックトレースを含まない理由 Goのerrorがスタックトレースを含まない理由 - methaneのブログ そういう思想や宗教ではなく慎重に調整している パフォーマンスの低下はそうですね
エラーのスタックトレースの歴史 https://speakerdeck.com/sonatard/go-error-trace
Webアプリケーションという立場から見ると カリカリチューニングが必要になっていないならまだいける 台数を並べればパフォーマンスを稼げる 可観測性が高いほうがメリットが大きい 他のプログラミング言語には当然スタックトレースがある
まとめ やっぱりスタックトレース欲しいやん みなさまはどのようにエラーと向き合っていますか?