Exception: Wolverine::LuaError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/wolverine/lua_error.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

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

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (LuaError) initialize(error, file)

Initialize a new Wolverine::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



24
25
26
27
28
29
30
31
32
33
# File 'lib/wolverine/lua_error.rb', line 24

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

  @error.message =~ PATTERN
  stage, line_number, message = $1, $2, $3

  super message
  set_backtrace generate_backtrace file, line_number
end

Class Method Details

+ (Boolean) intercepts?(error)

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?



15
16
17
# File 'lib/wolverine/lua_error.rb', line 15

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