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
63
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
Transcript
49 slides
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
More Decks by John Gallagher
See All by John Gallagher
Fix Production Bugs Quickly - Warsaw Ruby Conference 2024
johngallagher
0
23
Fix Bugs 20x Faster - Belfast Ruby 2025
johngallagher
0
19
Fix Production Bugs 20x Faster - The Wroclave.rb 2025
johngallagher
0
14
Using Monads for Elegant Error Handling - RubyConf 2021
johngallagher
0
22
Fix Production Bugs 20x Faster - Wroclave.rb - 2025
johngallagher
0
19
Squash Production Defects Quickly - The Power Of Structured Logging - EuRuKo 2024
johngallagher
0
18
Other Decks in Programming
See All in Programming
AIエージェントの「テストは通るのに本番で壊れる」を減らす
shibuiwilliam
3
130
Promiseの向こう側へコンテキストを届ける ― proposal-async-context
seriseri
0
850
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
470
Kotlin Fest 2026: Kotlin コンパイラに Contribute してみよう! - Kotlin/Wasm で深い再帰を書けるようにした話
ternbusty
1
430
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
510
Math.sumPreciseから学ぶ、ECMAScript仕様の数値の種類
syumai
0
1.3k
Crash Auto Pipelines
veronikapj
1
460
Claude Codeのおかげでやりたいことがやれるようになったんだよォー!
sms_tech
0
190
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
210
Canvas 2D Context Next
petamoriken
0
780
テストだけで見つかる? Rubyでつくるメソッド発掘器
izawa
0
170
動画プレイヤーはなぜカクつくのか 〜Flutterのレンダリングとネイティブの境界を解剖する〜
naruogram
0
350
Featured
See All Featured
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Designing for Performance
lara
612
70k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
340
A Modern Web Designer's Workflow
chriscoyier
699
190k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
670
The Curse of the Amulet
leimatthew05
4
17k
Why You Should Never Use an ORM
jnunemaker
PRO
61
10k
Large-scale JavaScript Application Architecture
addyosmani
516
110k
Highjacked: Video Game Concept Design
rkendrick25
PRO
2
600
Art, The Web, and Tiny UX
lynnandtonic
304
22k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k