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
0
43
Using Monads for Elegant Error Handling
John Gallagher
October 28, 2021
Tweet
Share
More Decks by John Gallagher
See All by John Gallagher
Fix Production Bugs Quickly - Warsaw Ruby Conference 2024
johngallagher
0
1
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
1
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
2
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
1
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
3
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
2
Other Decks in Programming
See All in Programming
複雑なドメインに挑む.pdf
yukisakai1225
5
1.2k
iOSDC.pdf
chronos2500
1
250
半自動E2Eで手っ取り早くリグレッションテストを効率化しよう
beryu
3
480
テストカバレッジ100%を10年続けて得られた学びと品質
mottyzzz
2
620
Compose Multiplatform × AI で作る、次世代アプリ開発支援ツールの設計と実装
thagikura
0
180
Testing Trophyは叫ばない
toms74209200
0
900
今だからこそ入門する Server-Sent Events (SSE)
nearme_tech
PRO
3
280
iOSからFlutterへ20代エンジニアの転身とWidget Preview実践
nappannda
0
110
概念モデル→論理モデルで気をつけていること
sunnyone
3
310
「待たせ上手」なスケルトンスクリーン、 そのUXの裏側
teamlab
PRO
0
610
ファインディ株式会社におけるMCP活用とサービス開発
starfish719
0
2.2k
AndroidXR向けにアプリを作るには
kotambourine
0
110
Featured
See All Featured
Visualization
eitanlees
148
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
46
7.6k
Intergalactic Javascript Robots from Outer Space
tanoku
272
27k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.6k
Why Our Code Smells
bkeepers
PRO
339
57k
Typedesign – Prime Four
hannesfritz
42
2.8k
Statistics for Hackers
jakevdp
799
220k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
Producing Creativity
orderedlist
PRO
347
40k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
16k
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