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
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
120
Takumiから考えるSecurity_Maturity_Model.pdf
gessy0129
1
130
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
440
Agentic AI: Evolution oder Revolution
mobilelarson
PRO
0
130
grapheme_strrev関数が採択されました(あと雑感)
youkidearitai
PRO
1
210
Event Storming
hschwentner
3
1.3k
AI Assistants for Your Angular Solutions
manfredsteyer
PRO
0
110
あなたはユーザーではない #PdENight
kajitack
4
340
Claude Code、ちょっとした工夫で開発体験が変わる
tigertora7571
0
200
受け入れテスト駆動開発(ATDD)×AI駆動開発 AI時代のATDDの取り組み方を考える
kztakasaki
2
550
Go Conference mini in Sendai 2026 : Goに新機能を提案し実装されるまでのフロー徹底解説
yamatoya
0
540
米国のサイバーセキュリティタイムラインと見る Goの暗号パッケージの進化
tomtwinkle
2
510
Featured
See All Featured
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
76
Visualization
eitanlees
150
17k
How to build an LLM SEO readiness audit: a practical framework
nmsamuel
1
660
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
100
Crafting Experiences
bethany
1
81
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.2k
HDC tutorial
michielstock
1
510
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
630
Marketing to machines
jonoalderson
1
5k
SEO for Brand Visibility & Recognition
aleyda
0
4.3k
Facilitating Awesome Meetings
lara
57
6.8k
DBのスキルで生き残る技術 - AI時代におけるテーブル設計の勘所
soudai
PRO
62
51k
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