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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
megane42
December 20, 2023
Programming
790
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rails deprecation warning に立ち向かう技術 / v.s. rails deprecation warnings
megane42
December 20, 2023
More Decks by megane42
See All by megane42
Immutable ActiveRecord
megane42
0
350
OSS コミットゴルフのすすめ / Let's play OSS-contribute-golf
megane42
0
130
ゆる計算理論ラジオ / P vs NP for beginner
megane42
1
270
How to Make "DJ giftee"
megane42
1
1k
Rails 6 Upgrade "Practical" Guide
megane42
6
1.4k
updated_at に依存したら大変なことになった / Don't depend on updated_at
megane42
0
630
本当は怖い Rails の `build_xxx` / The Hard Facts of `build_xxx` of Rails
megane42
0
290
Other Decks in Programming
See All in Programming
その問い、本当に正しいですか?AI時代のエンジニアに必要な哲学と認知科学 / ai-philosophy-cognitive-science
minodriven
11
5.9k
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
6
1.4k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
890
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
250
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
200
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
550
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
13k
気圧・高度・GPSを記録&可視化するアプリ「Koudo」を作った話
hjmkth
1
300
Oxlintのカスタムルールの現況
syumai
6
1.1k
Contextとはなにか
chiroruxx
1
330
AI 輔助遺留系統現代化的經驗分享
jame2408
1
810
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
290
Featured
See All Featured
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
200
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Paper Plane (Part 1)
katiecoart
PRO
0
9.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
160
AI: The stuff that nobody shows you
jnunemaker
PRO
8
720
How to Ace a Technical Interview
jacobian
281
24k
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
2.8k
Designing Powerful Visuals for Engaging Learning
tmiket
1
420
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
250
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 にイベント購読という概念があるのがおもしろい