Sha256: 78987ec13d6d57ae8398d015c7d3d011847ba51af154a1e0bc05837ad20539f7

Contents?: true

Size: 1.1 KB

Versions: 4

Compression:

Stored size: 1.1 KB

Contents

module Restruct
  class Error < StandardError
  end

  class ConnectionErrorFactory
    def self.create(exception)
      error_type = NoScriptError.match?(exception) ? NoScriptError : ConnectionError
      error_type.new exception
    end
  end

  class ConnectionError < Error

    def initialize(inner_exception)
      @inner_exception = inner_exception
    end

    def message
      @inner_exception.message
    end

    def backtrace
      @inner_exception.backtrace
    end

  end

  class NoScriptError < ConnectionError
    def self.match?(exception)
      exception.message.start_with? 'NOSCRIPT No matching script'
    end
  end

  class LockerError < Error

    def initialize(inner_exception)
      @inner_exception = inner_exception
    end

    def message
      @parsed_message ||= parse_message @inner_exception.message
    end

    def backtrace
      @inner_exception.backtrace
    end
    
    def parse_message(message)
      match_data = /^(ERR Error running script.*@user_script.*user_script.*: )/.match message
      match_data ? message.gsub(match_data.captures.first,'').strip : message
    end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
restruct-1.1.0 lib/restruct/errors.rb
restruct-1.0.0 lib/restruct/errors.rb
restruct-0.2.0 lib/restruct/errors.rb
restruct-0.1.0 lib/restruct/errors.rb