Module: Ignorable Private

Includes:
Kernel
Defined in:
ignorable.rb,
ignorable.rbi

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.

Defined Under Namespace

Modules: ExceptionMixin

Constant Summary

Constants included from Kernel

Kernel::IGNORE_INTERRUPTS_MUTEX

Class Method Summary collapse

Methods included from Kernel

#ensure_executable!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #quiet_system, #redirect_stdout, #safe_system, #which, #which_editor, #with_env, #with_homebrew_path

Class Method Details

.hook_raise(&blk) ⇒ void

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.

This method returns an undefined value.

Parameters:

  • blk (T.proc.void, nil)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'ignorable.rb', line 24

def self.hook_raise(&blk)
  # TODO: migrate away from this inline class here, they don't play nicely with
  #       Sorbet, when we migrate to `typed: strict`
  # rubocop:todo Sorbet/BlockMethodDefinition
  Object.class_eval do
    alias_method :original_raise, :raise

    sig { params(args: T.anything).void }
    def raise(*args)
      callcc do |continuation|
        super
      # Handle all possible exceptions.
      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
  # rubocop:enable Sorbet/BlockMethodDefinition

  return unless block_given?

  yield
  unhook_raise
end

.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.

This is a workaround to enable raise to be aliased



8
# File 'ignorable.rbi', line 8

def self.raise(*); end

.unhook_raisevoid

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.

This method returns an undefined value.



56
57
58
59
60
61
62
# File 'ignorable.rb', line 56

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