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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
John Gallagher
October 28, 2021
Programming
49
0
Share
Using Monads for Elegant Error Handling
John Gallagher
October 28, 2021
More Decks by John Gallagher
See All by John Gallagher
Fix Production Bugs Quickly - Warsaw Ruby Conference 2024
johngallagher
0
9
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
7
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
7
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
8
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
8
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
9
Other Decks in Programming
See All in Programming
inferと仲良くなる10分間
ryokatsuse
1
250
Zod v4 Codec でスキーマに型変換を埋め込む REST API 設計 #TSKaigi2026
ryutaro_yako
0
150
1人1案件のプロダクトエンジニア時代に、"プロセス監督"としてチャレンジしたこと
non0113
0
320
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
240
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
200
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
530
Inside Stream API
skrb
1
170
横断組織出身のQAEがインプロセスQAEでつまずいたこと・活かせたこと
ty89
0
180
サーバーレスで作る、動画データ管理基盤
oyasumipants
0
260
Modding RubyKaigi for Myself
yui_knk
0
440
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
5
980
今さら聞けないCancellationToken
htkym
0
190
Featured
See All Featured
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
54k
How to build a perfect <img>
jonoalderson
1
5.5k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
200
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
340
Prompt Engineering for Job Search
mfonobong
0
320
The Mindset for Success: Future Career Progression
greggifford
PRO
0
340
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.5k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
240
Raft: Consensus for Rubyists
vanstee
141
7.4k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
290
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
380
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
170
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