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
Rails deprecation warning に立ち向かう技術 / v.s. rails...
Search
megane42
December 20, 2023
Programming
0
660
Rails deprecation warning に立ち向かう技術 / v.s. rails deprecation warnings
megane42
December 20, 2023
Tweet
Share
More Decks by megane42
See All by megane42
Immutable ActiveRecord
megane42
0
240
OSS コミットゴルフのすすめ / Let's play OSS-contribute-golf
megane42
0
97
ゆる計算理論ラジオ / P vs NP for beginner
megane42
1
230
How to Make "DJ giftee"
megane42
1
920
Rails 6 Upgrade "Practical" Guide
megane42
6
1.4k
updated_at に依存したら大変なことになった / Don't depend on updated_at
megane42
0
590
本当は怖い Rails の `build_xxx` / The Hard Facts of `build_xxx` of Rails
megane42
0
260
Other Decks in Programming
See All in Programming
SwiftDataを使って10万件のデータを読み書きする
akidon0000
0
250
ボトムアップの生成AI活用を推進する社内AIエージェント開発
aku11i
0
1.4k
TFLintカスタムプラグインで始める Terraformコード品質管理
bells17
2
510
ビルドプロセスをデバッグしよう!
yt8492
0
180
マンガアプリViewerの大画面対応を考える
kk__777
0
440
Vue 3.6 時代のリアクティビティ最前線 〜Vapor/alien-signals の実践とパフォーマンス最適化〜
hiranuma
2
350
EMこそClaude Codeでコード調査しよう
shibayu36
0
520
オープンソースソフトウェアへの解像度🔬
utam0k
18
3.2k
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
120
When Dependencies Fail: Building Antifragile Applications in a Fragile World
selcukusta
0
120
Developer Joy - The New Paradigm
hollycummins
1
400
NIKKEI Tech Talk#38
cipepser
0
350
Featured
See All Featured
RailsConf 2023
tenderlove
30
1.3k
Gamification - CAS2011
davidbonilla
81
5.5k
A Modern Web Designer's Workflow
chriscoyier
697
190k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.1k
Building a Scalable Design System with Sketch
lauravandoore
463
33k
Docker and Python
trallard
46
3.6k
It's Worth the Effort
3n
187
28k
How to train your dragon (web standard)
notwaldorf
97
6.3k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.1k
Producing Creativity
orderedlist
PRO
348
40k
Keith and Marios Guide to Fast Websites
keithpitt
412
23k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
191
56k
Transcript
deprecation warning に ⽴ち向かう技術 2023/12/20 gotanda.rb #56 Hikaru Kazama (@megane42)
⾃⼰紹介 • ギフティのバックエンドエンジニア • 最近のコントリビュート:Kaigi on Rails アプリに⽬次を実装 • 実装⽇:最終⽇の翌⽇
課題 • Rails のバージョンアップに伴って、これまで使っていた機能 が deprecation (⾮推奨) になることがある • ぼんやりしているとログに吐かれた
deprecation warning を ⾒逃してしまい、後⽇実際に機能が削除 / 変更されてエラーが 起きてしまう
提案 • 実は deprecation warning が発⽣したときのふるまいを 変更できるので、変えてみましょう
config.active_support.deprecation • ⾮推奨機能を使ってしまったときのふるまいを定義できる • development / test 環境では :raise にしておくと便利
config.active_support.disallowed_deprecation • いきなり全体のふるまいを変えるのはちょっと… という⼈向け • 「この違反は潰した」というものだけを個別に設定すると、 その違反が再発したときだけ raise させたりできる
指定できるアクション • raise (エラーを発⽣) • stderr (標準エラーに出⼒) • log (ログに出⼒)
• notify (ActiveSupport::Notifications で通知) • silence (何もしない) https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html
指定できるアクション • raise (エラーを発⽣) • stderr (標準エラーに出⼒) • log (ログに出⼒)
• notify (ActiveSupport::Notifications で通知) • silence (何もしない) https://api.rubyonrails.org/classes/ActiveSupport/Deprecation/Behavior.html
ActiveSupport::Notifications • 実は Rails の中にはいろんなイベントが⾶び交っている • イベントを subscribe することで、任意の処理を実⾏できる •
initializers などで購読すればよい
Slack 通知してみるなど • 購読するイベントは `deprecation.rails` • `payload[:message]` から警告メッセージが取得可能 • `payload[:callstack]`
からスタックトレースが取得可能
正論 • deprecation warning なんて、テストカバレッジが⼗分⾼けれ ば、1 回テスト流すだけで検知できるんじゃないの?
正論 • deprecation warning なんて、テストカバレッジが⼗分⾼けれ ば、1 回テスト流すだけで検知できるんじゃないの?
まとめ • deprecation warning が発⽣しても、 デフォルトの挙動は単にログに吐くだけ • 設定を変更するとエラーを raise させられる
• 開発環境でおすすめ • 設定を変更するとイベント通知させられる • 本番環境でおすすめ • そもそも Rails にイベント購読という概念があるのがおもしろい