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
250
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
930
Rails 6 Upgrade "Practical" Guide
megane42
6
1.4k
updated_at に依存したら大変なことになった / Don't depend on updated_at
megane42
0
600
本当は怖い Rails の `build_xxx` / The Hard Facts of `build_xxx` of Rails
megane42
0
260
Other Decks in Programming
See All in Programming
しっかり学ぶ java.lang.*
nagise
1
390
Phronetic Team with AI - Agile Japan 2025 closing
hiranabe
2
620
オフライン対応!Flutterアプリに全文検索エンジンを実装する @FlutterKaigi2025
itsmedreamwalker
2
220
TVerのWeb内製化 - 開発スピードと品質を両立させるまでの道のり
techtver
PRO
3
1.1k
CSC509 Lecture 13
javiergs
PRO
0
250
What’s Fair is FAIR: A Decentralised Future for WordPress Distribution
rmccue
0
190
早すぎ?超先読み Go 1.26 Draft - Preview the contents of the Go 1.26 Draft Release Notes
tomtwinkle
0
320
Flutterチームから作る組織の越境文化
findy_eventslides
0
420
Querying Design System デザインシステムの意思決定を支える構造検索
ikumatadokoro
1
1.2k
Stay Hacker 〜九州で生まれ、Perlに出会い、コミュニティで育つ〜
pyama86
2
1.7k
Promise.tryで実現する新しいエラーハンドリング New error handling with Promise try
bicstone
3
480
モデル駆動設計をやってみよう Modeling Forum2025ワークショップ/Let’s Try Model-Driven Design
haru860
0
160
Featured
See All Featured
Rebuilding a faster, lazier Slack
samanthasiow
84
9.3k
Typedesign – Prime Four
hannesfritz
42
2.9k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
What's in a price? How to price your products and services
michaelherold
246
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.7k
Done Done
chrislema
186
16k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
24
1.6k
Designing for Performance
lara
610
69k
Documentation Writing (for coders)
carmenintech
76
5.1k
Navigating Team Friction
lara
190
15k
Embracing the Ebb and Flow
colly
88
4.9k
Context Engineering - Making Every Token Count
addyosmani
9
400
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 にイベント購読という概念があるのがおもしろい