Exception: Bearcat::RateLimiting::RedisScript::LuaError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/bearcat/rate_limiting/redis_script.rb

Overview

Reformats errors raised by redis representing failures while executing a lua script. The default errors have confusing messages and backtraces, and a type of RuntimeError. This class improves the message and modifies the backtrace to include the lua script itself in a reasonable way.

Constant Summary collapse

PATTERN =
/ERR Error (compiling|running) script \(.*?\): .*?:(\d+): (.*)/
WOLVERINE_LIB_PATH =
File.expand_path('../../', __FILE__)
CONTEXT_LINE_NUMBER =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, file, content) ⇒ LuaError

Initialize a new Bearcat::RateLimiting::RedisScript::LuaError from an existing redis error, adjusting the message and backtrace in the process.

Parameters:

  • error (StandardError)

    the original error raised by redis

  • file (Pathname)

    full path to the lua file the error ocurred in

  • content (String)

    lua file content the error ocurred in



118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 118

def initialize error, file, content
  @error = error
  @file = file
  @content = content

  @error.message =~ PATTERN
  _stage, line_number, message = $1, $2, $3
  error_context = generate_error_context(content, line_number.to_i)

  super "#{message}\n\n#{error_context}\n\n"
  set_backtrace generate_backtrace file, line_number
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



102
103
104
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 102

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error.



102
103
104
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 102

def error
  @error
end

#fileObject (readonly)

Returns the value of attribute file.



102
103
104
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 102

def file
  @file
end

Class Method Details

.intercepts?(error) ⇒ Boolean

Is this error one that should be reformatted?

Parameters:

  • error (StandardError)

    the original error raised by redis

Returns:

  • (Boolean)

    is this an error that should be reformatted?



108
109
110
# File 'lib/bearcat/rate_limiting/redis_script.rb', line 108

def self.intercepts? error
  error.message =~ PATTERN
end