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
580
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
170
OSS コミットゴルフのすすめ / Let's play OSS-contribute-golf
megane42
0
85
ゆる計算理論ラジオ / P vs NP for beginner
megane42
1
200
How to Make "DJ giftee"
megane42
1
880
Rails 6 Upgrade "Practical" Guide
megane42
6
1.3k
updated_at に依存したら大変なことになった / Don't depend on updated_at
megane42
0
540
本当は怖い Rails の `build_xxx` / The Hard Facts of `build_xxx` of Rails
megane42
0
180
Other Decks in Programming
See All in Programming
イベントソーシングとAIの親和性ー物語とLLMに理解できるデータ
tomohisa
1
150
クラス設計の手順
akikogoto
0
160
TypeScript製IaCツールのAWS CDKが様々な言語で実装できる理由 ~他言語変換の仕組み~ / cdk-language-transformation
gotok365
6
320
『Python → TypeScript』オンボーディング奮闘記
takumi_tatsuno
1
110
バリデーションライブラリ徹底比較
nayuta999999
1
200
生成AI時代のフルスタック開発
kenn
9
1.8k
「MCPを使ってる人」が より詳しくなるための解説
yamaguchidesu
0
280
Devinで実践する!AIエージェントと協働する開発組織の作り方
masahiro_nishimi
5
1.3k
Cloudflare Workersで進めるリモートMCP活用
syumai
13
1.8k
ソフトウェア品質特性、意識してますか?AIの真の力を引き出す活用事例 / ai-and-software-quality
minodriven
19
6.2k
VibeCoding時代のエンジニアリング
daisuketakeda
0
300
ビカム・ア・コパイロット
ymd65536
1
180
Featured
See All Featured
Unsuck your backbone
ammeep
671
58k
Raft: Consensus for Rubyists
vanstee
137
6.9k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
41
2.3k
Agile that works and the tools we love
rasmusluckow
329
21k
Building Flexible Design Systems
yeseniaperezcruz
329
39k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Writing Fast Ruby
sferik
628
61k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
The Illustrated Children's Guide to Kubernetes
chrisshort
48
50k
Rails Girls Zürich Keynote
gr2m
94
13k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
45
9.5k
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 にイベント購読という概念があるのがおもしろい