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
54
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
11
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
7
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
11
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
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
630
これって Effect でできたのでは? / TSKaigi Mashup Kansai #2
susisu
0
140
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.5k
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
3.4k
琵琶湖の水は止められてもNet--HTTPのリトライは止められない / You might be able to stop the water flow of Lake Biwa but you can't stop Net::HTTP retries
luccafort
PRO
0
520
Lean は証明の正しさを確認するためだけのツールって思ってませんか?
inoueasei
1
130
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
560
PHP に部分適用が来るぞ!……ところで何それ?おいしいの? #phpcon / phpcon-2026
shogogg
0
500
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
930
わからない話を追いかけたら、プログラミング言語を作る側にいた
ydah
3
390
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
410
komatsuna「分散システムにおけるバグ分析手法」
komatsunaqa
0
150
Featured
See All Featured
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
280
Evolving SEO for Evolving Search Engines
ryanjones
0
250
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Darren the Foodie - Storyboard
khoart
PRO
3
3.5k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.5k
Building Adaptive Systems
keathley
44
3.2k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
550
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.1k
Designing Experiences People Love
moore
143
24k
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