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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
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
20260127_試行錯誤の結晶を1冊に。著者が解説 先輩データサイエンティストからの指南書 / author's_commentary_ds_instructions_guide
nash_efp
1
980
CSC307 Lecture 09
javiergs
PRO
1
840
CSC307 Lecture 04
javiergs
PRO
0
660
CSC307 Lecture 01
javiergs
PRO
0
690
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
460
AWS re:Invent 2025参加 直前 Seattle-Tacoma Airport(SEA)におけるハードウェア紛失インシデントLT
tetutetu214
2
110
プロダクトオーナーから見たSOC2 _SOC2ゆるミートアップ#2
kekekenta
0
220
なるべく楽してバックエンドに型をつけたい!(楽とは言ってない)
hibiki_cube
0
140
要求定義・仕様記述・設計・検証の手引き - 理論から学ぶ明確で統一された成果物定義
orgachem
PRO
1
140
Architectural Extensions
denyspoltorak
0
290
そのAIレビュー、レビューしてますか? / Are you reviewing those AI reviews?
rkaga
6
4.6k
登壇資料を作る時に意識していること #登壇資料_findy
konifar
4
1.2k
Featured
See All Featured
What does AI have to do with Human Rights?
axbom
PRO
0
2k
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
0
140
sira's awesome portfolio website redesign presentation
elsirapls
0
150
4 Signs Your Business is Dying
shpigford
187
22k
Everyday Curiosity
cassininazir
0
130
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
1
130
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
250
A Soul's Torment
seathinner
5
2.3k
Building Adaptive Systems
keathley
44
2.9k
How to make the Groovebox
asonas
2
1.9k
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
96
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.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