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
51
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
11
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
8
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
7
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
9
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
9
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
9
Other Decks in Programming
See All in Programming
dRuby over BLE
makicamel
2
330
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
390
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.2k
軽量Java基盤の設計 DIコンテナに頼らない、長期保守と1秒起動の実現 JJUG CCC 2026 Spring
macha64
0
490
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
660
Agentic UI
manfredsteyer
PRO
0
140
CSC307 Lecture 17
javiergs
PRO
0
320
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
180
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
530
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
570
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
690
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1.2k
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
57
14k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
540
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
A Soul's Torment
seathinner
6
2.9k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3.4k
Documentation Writing (for coders)
carmenintech
77
5.4k
BBQ
matthewcrist
89
10k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
280
Money Talks: Using Revenue to Get Sh*t Done
nikkihalliwell
0
250
How GitHub (no longer) Works
holman
316
150k
The World Runs on Bad Software
bkeepers
PRO
72
12k
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