From a78051d2e0586eacc12c6d55ceb467ccec11aa4b Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Wed, 7 Apr 2021 02:14:55 +0100 Subject: [PATCH] debrew: make Debrew::Raise only catch uncaught exceptions --- Library/Homebrew/debrew.rb | 27 +++++++++++++++++++++------ Library/Homebrew/formula_installer.rb | 1 - 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb index b19cac13cb..82407ecbc2 100644 --- a/Library/Homebrew/debrew.rb +++ b/Library/Homebrew/debrew.rb @@ -3,6 +3,10 @@ require "mutex_m" require "debrew/irb" +require "warnings" +Warnings.ignore(/warning: callcc is obsolete; use Fiber instead/) do + require "continuation" +end # Helper module for debugging formulae. # @@ -10,15 +14,26 @@ require "debrew/irb" module Debrew extend Mutex_m - Ignorable = Module.new.freeze + # Marks exceptions which can be ignored and provides + # the ability to jump back to where it was raised. + module Ignorable + attr_accessor :continuation + + def ignore + continuation.call + end + end # Module for allowing to ignore exceptions. module Raise def raise(*) - super - rescue Exception => e # rubocop:disable Lint/RescueException - e.extend(Ignorable) - super(e) unless Debrew.debug(e) == :ignore + callcc do |continuation| + super + rescue Exception => e # rubocop:disable Lint/RescueException + e.extend(Ignorable) + e.continuation = continuation + super(e) + end end alias fail raise @@ -105,7 +120,7 @@ module Debrew rescue SystemExit original_raise rescue Exception => e # rubocop:disable Lint/RescueException - debug(e) + e.ignore if debug(e) == :ignore # execution jumps back to where the exception was thrown ensure @active = false end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index b194865a05..0d5bfd8074 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -9,7 +9,6 @@ require "caveats" require "cleaner" require "formula_cellar_checks" require "install_renamed" -require "debrew" require "sandbox" require "development_tools" require "cache_store"