Exception: SidekiqUniqueJobs::Script::LuaError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/sidekiq_unique_jobs/script/lua_error.rb

Overview

LuaError raised on errors in Lua scripts

Author:

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.expand_path("..", __dir__).freeze
CONTEXT_LINE_NUMBER =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error, script) ⇒ LuaError

Initialize a new SidekiqUniqueJobs::Script::LuaError from an existing redis error, adjusting the message and backtrace in the process.

Parameters:

  • error (StandardError)

    the original error raised by redis

  • script (Script)

    a DTO with information about the script



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/sidekiq_unique_jobs/script/lua_error.rb', line 43

def initialize(error, script)
  @error        = error
  @file         = script.path
  @content      = script.source
  @backtrace    = @error.backtrace

  @error.message.match(PATTERN) do |regexp_match|
    line_number   = regexp_match[2].to_i
    message       = regexp_match[3]
    error_context = generate_error_context(content, line_number)

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

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



27
28
29
# File 'lib/sidekiq_unique_jobs/script/lua_error.rb', line 27

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error.



27
28
29
# File 'lib/sidekiq_unique_jobs/script/lua_error.rb', line 27

def error
  @error
end

#fileObject (readonly)

Returns the value of attribute file.



27
28
29
# File 'lib/sidekiq_unique_jobs/script/lua_error.rb', line 27

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?



33
34
35
# File 'lib/sidekiq_unique_jobs/script/lua_error.rb', line 33

def self.intercepts?(error)
  PATTERN.match?(error.message)
end