Module: Ignorable Private

Defined in:
ignorable.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Provides the ability to optionally ignore errors raised and continue execution.

Defined Under Namespace

Modules: ExceptionMixin

Class Method Summary collapse

Class Method Details

.hook_raiseObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'ignorable.rb', line 23

def self.hook_raise
  Object.class_eval do
    alias_method :original_raise, :raise

    def raise(*)
      callcc do |continuation|
        super
      rescue Exception => e # rubocop:disable Lint/RescueException
        unless e.is_a?(ScriptError)
          e.extend(ExceptionMixin)
          T.cast(e, ExceptionMixin).continuation = continuation
        end
        super(e)
      end
    end

    alias_method :fail, :raise
  end

  return unless block_given?

  yield
  unhook_raise
end

.unhook_raiseObject

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.



48
49
50
51
52
53
54
# File 'ignorable.rb', line 48

def self.unhook_raise
  Object.class_eval do
    alias_method :raise, :original_raise
    alias_method :fail, :original_raise
    undef :original_raise
  end
end