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
Using Monads for Elegant Error Handling
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
John Gallagher
October 28, 2021
Programming
0
45
Using Monads for Elegant Error Handling
John Gallagher
October 28, 2021
Tweet
Share
More Decks by John Gallagher
See All by John Gallagher
Fix Production Bugs Quickly - Warsaw Ruby Conference 2024
johngallagher
0
4
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
4
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
4
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
4
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
4
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
4
Other Decks in Programming
See All in Programming
dchart: charts from deck markup
ajstarks
3
990
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
7.4k
Data-Centric Kaggle
isax1015
2
780
開発者から情シスまで - 多様なユーザー層に届けるAPI提供戦略 / Postman API Night Okinawa 2026 Winter
tasshi
0
200
組織で育むオブザーバビリティ
ryota_hnk
0
180
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
140
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
460
AgentCoreとHuman in the Loop
har1101
5
240
インターン生でもAuth0で認証基盤刷新が出来るのか
taku271
0
190
AI時代のキャリアプラン「技術の引力」からの脱出と「問い」へのいざない / tech-gravity
minodriven
21
7.3k
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
690
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.3k
Become a Pro
speakerdeck
PRO
31
5.8k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Writing Fast Ruby
sferik
630
62k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
52k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
640
Building a Scalable Design System with Sketch
lauravandoore
463
34k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.2k
Transcript
Using Monads for Elegant Error Handling John Gallagher
None
None
None
None
None
None
Failure modes? Caught all exceptions? Customer experience?
Example - Address Editing Find contact Lookup postcode* Success? Render
manual entry Render select Success? Render error Yes Yes No No * Postcode - zip code in the US
Exceptions
Exceptions
Exceptions
Problems Returning nil harmful Client knows too much No return
value convention Customers: broken software You: doubt, decision fatigue
What is a Result Monad? Represents success or failure Consistent
interface Wraps value or error
Refactor to Monads
Success and Failure
None
None
Exceptions
Monads
Exceptions
Monads
Exceptions
Monads
Convert to pipeline
Handle success with .fmap
None
None
Handle failure with .or
None
None
Chain .fmap and .or
None
None
Monads
Monads and Pipeline
Exceptions Monads
None
Turn it up to eleven!
Turn it up to eleven!
Benefits Readable pipeline Scales well Helps thinking Failures store errors
Drawbacks More boilerplate code More dependencies Not idiomatic Ruby More
to understand
None
Quiz
Question 1 Answer: C
Question 2 Answer: A
Practice https://bit.ly/eleganterrors Run through the exercise Submit a PR Ask
any questions
Thank you! John Gallagher Lead Developer, BiggerPockets Automation Consultant, Synaptic
Mishap Twitter: @synapticmishap LinkedIn: @synapticmishap Github: @johngallagher
Do notation Try Check out the docs for Dry Monads