Sha256: 34000b0244b5b8a963169c08a00441ff194a28b272030593c69aa40261d408fd

Contents?: true

Size: 1.35 KB

Versions: 29

Compression:

Stored size: 1.35 KB

Contents

module Methadone
  # Standard exception you can throw to exit with a given 
  # status code. Generally, you should prefer Methadone::Main#exit_now! over using
  # this directly, however you may wish to create a rich hierarchy of exceptions that extend from
  # this in your app, so this is provided if you wish to do so.
  class Error < StandardError
    attr_reader :exit_code
    # Create an Error with the given status code and message
    def initialize(exit_code,message=nil)
      super(message)
      @exit_code = exit_code
    end
  end

  # Thrown by certain methods when an externally-called command exits nonzero
  class FailedCommandError < Error

    # The command that caused the failure
    attr_reader :command

    # exit_code:: exit code of the command that caused this
    # command:: the entire command-line that caused this
    # custom_error_message:: an error message to show the user instead of the boilerplate one.  Useful
    #                        for allowing this exception to bubble up and exit the program, but to give
    #                        the user something actionable.
    def initialize(exit_code,command,custom_error_message = nil)
      error_message = String(custom_error_message).empty? ?  "Command '#{command}' exited #{exit_code}" : custom_error_message
      super(exit_code,error_message)
      @command = command
    end
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
methadone-2.0.2 lib/methadone/error.rb
methadone-2.0.1 lib/methadone/error.rb
methadone-2.0.0 lib/methadone/error.rb
methadone-1.9.5 lib/methadone/error.rb
methadone-1.9.4 lib/methadone/error.rb
methadone-1.9.3 lib/methadone/error.rb
methadone-1.9.2 lib/methadone/error.rb
methadone-rehab-1.9.2 lib/methadone/error.rb
methadone-1.9.1 lib/methadone/error.rb
methadone-1.9.0 lib/methadone/error.rb
methadone-1.8.0 lib/methadone/error.rb
methadone-1.7.0 lib/methadone/error.rb
methadone-1.6.0 lib/methadone/error.rb
methadone-1.5.1 lib/methadone/error.rb
methadone-1.5.0 lib/methadone/error.rb
methadone-1.4.0 lib/methadone/error.rb
methadone-1.3.2 lib/methadone/error.rb
methadone-1.3.1 lib/methadone/error.rb
methadone-1.3.0 lib/methadone/error.rb
methadone-1.2.6 lib/methadone/error.rb