Exception: Brpoplpush::RedisScript::LuaError
- Inherits:
-
RuntimeError
- Object
- RuntimeError
- Brpoplpush::RedisScript::LuaError
- Defined in:
- lib/brpoplpush/redis_script/lua_error.rb
Overview
LuaError raised on errors in Lua scripts
Constant Summary collapse
- PATTERN =
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. /ERR Error (compiling|running) script \(.*?\): .*?:(\d+): (.*)/.freeze
- LIB_PATH =
File.("..", __dir__).freeze
- CONTEXT_LINE_NUMBER =
2
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
Class Method Summary collapse
-
.intercepts?(error) ⇒ Boolean
Is this error one that should be reformatted?.
Instance Method Summary collapse
-
#initialize(error, script) ⇒ LuaError
constructor
Initialize a new LuaError from an existing redis error, adjusting the message and backtrace in the process.
Constructor Details
#initialize(error, script) ⇒ LuaError
Initialize a new Brpoplpush::RedisScript::LuaError from an existing redis error, adjusting the message and backtrace in the process.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/brpoplpush/redis_script/lua_error.rb', line 43 def initialize(error, script) @error = error @file = script.path @content = script.source @backtrace = @error.backtrace @error..match(PATTERN) do |regexp_match| line_number = regexp_match[2].to_i = regexp_match[3] error_context = generate_error_context(content, line_number) super("#{}\n\n#{error_context}\n\n") set_backtrace(generate_backtrace(file, line_number)) end end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
27 28 29 |
# File 'lib/brpoplpush/redis_script/lua_error.rb', line 27 def content @content end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
27 28 29 |
# File 'lib/brpoplpush/redis_script/lua_error.rb', line 27 def error @error end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
27 28 29 |
# File 'lib/brpoplpush/redis_script/lua_error.rb', line 27 def file @file end |
Class Method Details
.intercepts?(error) ⇒ Boolean
Is this error one that should be reformatted?
33 34 35 |
# File 'lib/brpoplpush/redis_script/lua_error.rb', line 33 def self.intercepts?(error) PATTERN.match?(error.) end |