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
半永久的に提供し続けられるプライベートクラウドを目指して ― 利用者の認知負荷を抑えるAPI抽象化とハードウェア世代交代の基盤設計
tomokon
0
500
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
350
JIS keyboard support in Omarchy
lef237
0
120
コーディング自動化の次へ。人の介入をゼロにするファクトリーとサポートAIによる実践
timakin
5
3.6k
Verilogで学ぶCPU自作入門
uyuki234
8
4.1k
ActionController meets Protocol Buffers
sorah
0
530
RAG の “R” を Swift で覗いてみる 〜「意味から探す」検索の仕組み〜
nao_randd
0
160
npm との違いを手がかりにGo の依存管理を理解したい
optim
0
360
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
残高管理から台帳サービスへの進化
artoy
1
200
Workers Cache を知る
syumai
0
360
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
190
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
Heart Work Chapter 1 - Part 1
lfama
PRO
10
37k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
310
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
460
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Optimising Largest Contentful Paint
csswizardry
37
4k
The Limits of Empathy - UXLibs8
cassininazir
2
720
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
203
77k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
430
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Effective software design: The role of men in debugging patriarchy in IT @ Voxxed Days AMS
baasie
1
570
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