$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Using Monads for Elegant Error Handling
Search
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
3
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
3
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
HTTPプロトコル正しく理解していますか? 〜かわいい猫と共に学ぼう。ฅ^•ω•^ฅ ニャ〜
hekuchan
2
470
perlをWebAssembly上で動かすと何が嬉しいの??? / Where does Perl-on-Wasm actually make sense?
mackee
0
150
tsgolintはいかにしてtypescript-goの非公開APIを呼び出しているのか
syumai
7
2.4k
AIエンジニアリングのご紹介 / Introduction to AI Engineering
rkaga
8
3.4k
AIコーディングエージェント(skywork)
kondai24
0
210
Developing static sites with Ruby
okuramasafumi
0
330
「コードは上から下へ読むのが一番」と思った時に、思い出してほしい話
panda728
PRO
39
26k
TerraformとStrands AgentsでAmazon Bedrock AgentCoreのSSO認証付きエージェントを量産しよう!
neruneruo
4
1.8k
Graviton と Nitro と私
maroon1st
0
140
実はマルチモーダルだった。ブラウザの組み込みAI🧠でWebの未来を感じてみよう #jsfes #gemini
n0bisuke2
3
1.3k
JETLS.jl ─ A New Language Server for Julia
abap34
2
460
2年のAppleウォレットパス開発の振り返り
muno92
PRO
0
100
Featured
See All Featured
[SF Ruby Conf 2025] Rails X
palkan
0
640
Mind Mapping
helmedeiros
PRO
0
39
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
200
GitHub's CSS Performance
jonrohan
1032
470k
Reality Check: Gamification 10 Years Later
codingconduct
0
1.9k
Claude Code のすすめ
schroneko
67
210k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
130
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
29
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
81
Navigating Team Friction
lara
191
16k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
1
210
sira's awesome portfolio website redesign presentation
elsirapls
0
90
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