Sha256: ad5acfea0b6c7fa690db3fa52c7d8b9ebcae87782446aae5baf54f628282ecfb

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

---
title: Tracing failures
layout: gem-single
name: dry-monads
---

"Left" values of right-biased monads like `Maybe` and `Result` (as in, `None()` and `Failure()`) ignore blocks passed to `fmap` and `bind`. Because of this, these values travel across the application without any modification. If the place where a `Failure` was constructed is burried somewhere deep in the app or library code it may be pretty hard to find out where exactly the error occurred.

This is a noticable downside compared to "good" old exceptions. To address it, every `Failure(...)` and `None()` value tracks the line where it was created:

```ruby
# create_user.rb
require 'dry/monads'

class CreateUser
  include Dry::Monads[:result]

  def call
    Failure(:no_luck)
  end
end
```

```ruby
require 'create_user'

create_user = CreateUser.new
create_user.()       # => Failure(:no_luck)
create_user.().trace # => .../create_user.rb:8:in `call'
```

Note that the trace stores only one line of the stack so it shouldn't ever be a performance issue.

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-monads-1.3.5 docsite/source/tracing-failures.html.md
dry-monads-1.3.4 docsite/source/tracing-failures.html.md
dry-monads-1.3.3 docsite/source/tracing-failures.html.md
dry-monads-1.3.2 docsite/source/tracing-failures.html.md