Sha256: 5da7dbc4eb9c554b1ca36afad880aec55d72995c8e02d2eef85cc16e1c207e32

Contents?: true

Size: 1.94 KB

Versions: 6770

Compression:

Stored size: 1.94 KB

Contents

# frozen_string_literal: true

require_relative "../command"
require_relative "../helpers/eval"

module Byebug
  #
  # Implements exception catching.
  #
  # Enables the user to catch unhandled assertion when they happen.
  #
  class CatchCommand < Command
    include Helpers::EvalHelper

    self.allow_in_post_mortem = true

    def self.regexp
      /^\s* cat(?:ch)? (?:\s+(\S+))? (?:\s+(off))? \s*$/x
    end

    def self.description
      <<-DESCRIPTION
        cat[ch][ (off|<exception>[ off])]

        #{short_description}

        catch                 -- lists catchpoints
        catch off             -- deletes all catchpoints
        catch <exception>     -- enables handling <exception>
        catch <exception> off -- disables handling <exception>
      DESCRIPTION
    end

    def self.short_description
      "Handles exception catchpoints"
    end

    def execute
      return info unless @match[1]

      return @match[1] == "off" ? clear : add(@match[1]) unless @match[2]

      return errmsg pr("catch.errors.off", off: cmd) unless @match[2] == "off"

      remove(@match[1])
    end

    private

    def remove(exception)
      return errmsg pr("catch.errors.not_found", exception: exception) unless Byebug.catchpoints.member?(exception)

      puts pr("catch.removed", exception: exception)
      Byebug.catchpoints.delete(exception)
    end

    def add(exception)
      errmsg pr("catch.errors.not_class", class: exception) if warning_eval(exception.is_a?(Class).to_s)

      puts pr("catch.added", exception: exception)
      Byebug.add_catchpoint(exception)
    end

    def clear
      Byebug.catchpoints.clear if confirm(pr("catch.confirmations.delete_all"))
    end

    def info
      if Byebug.catchpoints && !Byebug.catchpoints.empty?
        Byebug.catchpoints.each_key do |exception|
          puts("#{exception}: #{exception.is_a?(Class)}")
        end
      else
        puts "No exceptions set to be caught."
      end
    end
  end
end

Version data entries

6,770 entries across 6,767 versions & 30 rubygems

Version Path
ory-client-0.0.1.alpha57 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha56 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha55 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha54 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha53 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha52 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha51 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha50 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha49 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha48 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha47 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha46 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha45 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha44 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha43 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha42 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha41 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha40 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha39 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb
ory-client-0.0.1.alpha38 vendor/bundle/ruby/2.5.0/gems/byebug-11.1.3/lib/byebug/commands/catch.rb