Skip to content

Commit

Permalink
Merge pull request #18 from Kaligo/bugfix/make-guard-fail-not-acciden…
Browse files Browse the repository at this point in the history
…tally-catchable

Have GuardFailed inherit from Exception instead of StandardError
  • Loading branch information
Drenmi authored Oct 25, 2021
2 parents 93c69f0 + ee776a4 commit 81df8a1
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
# Changelog

## 0.8.2

### Bug fixes

- Have `GuardFailed` inherit from `Exception` instead of `StandardError`.

## 0.8.1

## Maintenance
- Loosen the ActiveSupport dependency version to prepare for Rails 7.

## 0.8.0

### New features
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PATH
remote: .
specs:
stimpack (0.8.0)
stimpack (0.8.1)
activesupport (>= 6.1)

GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.4)
activesupport (6.1.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,7 @@ long as the guards return a success `Result`, the execution continues as
expected.

*Note: Any error callbacks declared on the inner monad will also be invoked.*

Guard clauses use `raise` and `rescue` internally, but the exception used is
directly inherited from `Exception`, so it is safe to rescue anything downstream
of that, e.g. `StandardError` in your methods which have guard clauses.
2 changes: 1 addition & 1 deletion lib/stimpack/result_monad/guard_clause.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def call
# guard fails. It carries the error result with it, and passes it to the
# caller which can then work with it.
#
class GuardFailed < StandardError
class GuardFailed < Exception # rubocop:disable Lint/InheritException
# rubocop:disable Lint/MissingSuper
def initialize(result)
@result = result
Expand Down
2 changes: 1 addition & 1 deletion lib/stimpack/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Stimpack
VERSION = "0.8.1"
VERSION = "0.8.2"
end
2 changes: 2 additions & 0 deletions spec/stimpack/result_monad/guard_clause_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def call
baz_result = guard { baz }

success(foo: bar_result + baz_result)
rescue StandardError
error(errors: "Something went wrong, but not a guard fail.")
end

private
Expand Down

0 comments on commit 81df8a1

Please sign in to comment.