Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Using Monads for Elegant Error Handling
Search
John Gallagher
October 28, 2021
Programming
57
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
17
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
13
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
8
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
15
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
14
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
11
Other Decks in Programming
See All in Programming
全ての永続トークンを、生まれる前に消し去りたい!
sylph01
2
890
AIに “答え“を書かせるのを やめてみた
___akari11
0
120
ハーネス設計入門 〜 基礎知識の整理から実務へのステップアップ 〜
kinopeee
28
32k
IBM Bob でAI駆動開発『QC-Playbook』
ichirokano2
0
110
contenteditable と日本語入力に向き合う
colorful12
0
200
気持ちぃ〜角丸 Squircle
ryu1013
0
310
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
2
150
Agents on Rails - Rails at Scale 2026
irinanazarova
0
560
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
残高管理から台帳サービスへの進化
artoy
1
200
ChromeでローカルLLM
ryu1013
0
140
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Odyssey Design
rkendrick25
PRO
2
870
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
710
The World Runs on Bad Software
bkeepers
PRO
72
12k
Abbi's Birthday
coloredviolet
4
10k
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
2
6.3k
Why Our Code Smells
bkeepers
PRO
340
58k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
940
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
GitHub's CSS Performance
jonrohan
1033
470k
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