From ee776a452684ab1ad493250e68eb18a7796a26c4 Mon Sep 17 00:00:00 2001 From: Ted Johansson Date: Fri, 22 Oct 2021 16:04:15 +0800 Subject: [PATCH] Have GuardFailed inherit from Exception instead of StandardError --- CHANGELOG.md | 11 +++++++++++ Gemfile.lock | 4 ++-- README.md | 4 ++++ lib/stimpack/result_monad/guard_clause.rb | 2 +- lib/stimpack/version.rb | 2 +- spec/stimpack/result_monad/guard_clause_spec.rb | 2 ++ 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 661fb54..fc2a5e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Gemfile.lock b/Gemfile.lock index d385718..c1e83ff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -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) diff --git a/README.md b/README.md index 0cc1916..14df7fd 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/lib/stimpack/result_monad/guard_clause.rb b/lib/stimpack/result_monad/guard_clause.rb index 5461523..247f8ad 100644 --- a/lib/stimpack/result_monad/guard_clause.rb +++ b/lib/stimpack/result_monad/guard_clause.rb @@ -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 diff --git a/lib/stimpack/version.rb b/lib/stimpack/version.rb index a871f53..0d6d882 100644 --- a/lib/stimpack/version.rb +++ b/lib/stimpack/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Stimpack - VERSION = "0.8.1" + VERSION = "0.8.2" end diff --git a/spec/stimpack/result_monad/guard_clause_spec.rb b/spec/stimpack/result_monad/guard_clause_spec.rb index ce198f5..1bfeadb 100644 --- a/spec/stimpack/result_monad/guard_clause_spec.rb +++ b/spec/stimpack/result_monad/guard_clause_spec.rb @@ -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