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
John Gallagher
October 28, 2021
Programming
48
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
7
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
8
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
7
Other Decks in Programming
See All in Programming
The Less-Told Story of Socket Timeouts
coe401_
3
580
GoogleCloudとterraform完全に理解した
terisuke
1
140
[RubyKaigi 2026] Require Hooks
palkan
1
220
ルールルルルルRubyの中身の予備知識 ── RubyKaigiの前に予習しなイカ?
ydah
1
210
PCOVから学ぶコードカバレッジ #phpcon_odawara
o0h
PRO
0
280
Angular Signal Forms
debug_mode
0
110
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
150
Kingdom of the Machine
yui_knk
2
750
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.6k
TiDBのアーキテクチャから学ぶ分散システム入門 〜MySQL互換のNewSQLは何を解決するのか〜 / tidb-architecture-study
dznbk
1
180
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
190
セグメントとターゲットを意識するプロポーザルの書き方 〜採択の鍵は、誰に刺すかを見極めるマーケティング戦略にある〜
m3m0r7
PRO
0
570
Featured
See All Featured
First, design no harm
axbom
PRO
2
1.2k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
1.9k
Technical Leadership for Architectural Decision Making
baasie
3
330
New Earth Scene 8
popppiees
3
2.1k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.9k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
Between Models and Reality
mayunak
3
270
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.4k
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
350
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
27
3.4k
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