module DTK::Client::GitRepo::Adapter::GitGem::ErrorHandler

Constants

GitErrorPattern

Public Class Methods

handle_git_error() { || ... } click to toggle source
# File lib/client/git_repo/adapter/git_gem/error_handler.rb, line 29
def self.handle_git_error(&block)
  begin
    yield
   rescue => e
    unless e.respond_to?(:message)
      raise e
    else
      raise Error::Usage, user_friendly_message(e.message)
    end
  end
end

Private Class Methods

user_friendly_message(message) click to toggle source
# File lib/client/git_repo/adapter/git_gem/error_handler.rb, line 43
def self.user_friendly_message(message)
  user_friendly_message = 
    case message
    when /repository not found/i
      "Repository not found"
    when /repository (.*) not found/i
      "Repository #{$1.strip()} not found"
    when /destination path (.*) already exists/i
      "Destination folder #{$1.strip()} already exists"
    when /Authentication failed for (.*)$/i
      "Authentication failed for given repository #{$1.strip()}"
    when /timed out/
      "Timeout - not able to contact remote"
    else
      lines = message.split("\n")
      if lines.last =~ GitErrorPattern
        last_line = message.last.gsub(GitErrorPattern,'').strip
        if last_line =~ /adding files failed/ and lines.first =~ /\.git/
          "Cannot add files that are in a .git directory; remove any nested .git directory'"
        end
      end
    end
  user_friendly_message || message
end