Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Using Monads for Elegant Error Handling - RubyC...

Using Monads for Elegant Error Handling - RubyConf 2021

Your app blows up in production. It's an outage and you're under pressure. You read the code. "How does this work? Why is this exception being caught here?" And so begins a long, stressful journey to understand how to fix your code.

Rescuing exceptions is normalised in Ruby, but it's a clumsy way of reacting to error conditions and causes your code to be difficult to reason about.

You'll refactor an existing app to use a functional style and see first hand how easy monads are to use and how they can make your code incredibly clean and expressive.

Avatar for John Gallagher

John Gallagher

June 11, 2025
Tweet

More Decks by John Gallagher

Other Decks in Programming

Transcript

  1. 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
  2. Problems Returning nil harmful Client knows too much No return

    value convention Customers: broken software You: doubt, decision fatigue
  3. Thank you! John Gallagher Lead Developer, BiggerPockets Automation Consultant, Synaptic

    Mishap Twitter: @synapticmishap LinkedIn: @synapticmishap Github: @johngallagher