Skip to content

Commit 22222d2

Browse files
Fix docs on error handling (#32)
The second argument to `#on_failure` is the method name that defines the whole operation, not the step that failed. This is because a single class can define multiple operations.
1 parent e10b804 commit 22222d2

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

docsite/source/error-handling.html.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CreateUser < Dry::Operation
3434
end
3535
```
3636

37-
The `#on_failure` method can optionally accept a second argument that indicates which method encountered the failure, allowing you more granular control over error handling:
37+
The `#on_failure` method can optionally accept a second argument that indicates which method encountered the failure. This is helpful if you're defining more than an operation in a class:
3838

3939
```ruby
4040
class CreateUser < Dry::Operation
@@ -52,14 +52,7 @@ class CreateUser < Dry::Operation
5252
private
5353

5454
def on_failure(failure, step_name)
55-
case step_name
56-
when :validate
57-
logger.error("Validation failed: #{failure}")
58-
when :persist
59-
logger.error("Persistence failed: #{failure}")
60-
when :notify
61-
logger.error("Notification failed: #{failure}")
62-
end
55+
# step_name is going to be `:call` here
6356
end
6457
end
6558
```

0 commit comments

Comments
 (0)