Module: DbAgile::Environment::OnError

Included in:
DbAgile::Environment
Defined in:
lib/dbagile/environment/on_error.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#show_backtrace=(value) ⇒ Object (writeonly)

Show backtrace on errors?



6
7
8
# File 'lib/dbagile/environment/on_error.rb', line 6

def show_backtrace=(value)
  @show_backtrace = value
end

Instance Method Details

#on_error(command, error) ⇒ Object

Handles an error that occured during command execution.

Parameters:

  • error (Exception)

    the error that was raised

Returns:

  • nil to continue execution, an error to raise otherwise



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/dbagile/environment/on_error.rb', line 19

def on_error(command, error)
  case error
    when SystemExit
    when OptionParser::ParseError
      say(error.message, :red)
      display(command.options.to_s)
    when Sequel::Error, IOError
      say(error.message, :red)
    when DbAgile::SchemaSemanticsError
      say(error.message(true), :red)
    when DbAgile::InternalError
      say("DbAgile encountered an internal error.\n Please replay with dba --backtrace and report the error!", :red)
      say(error.message, :red)
    when DbAgile::Error
      say(error.message, :red)
    when Interrupt
      say("Command interrupted by user", :magenta)
    else
      say("ERROR (#{error.class}): #{error.message}", :red)
  end
  if show_backtrace?
    say(error.backtrace.join("\n"))
  end
  error
end

#show_backtrace?Boolean

Shows the backtrace when an error occurs?

Returns:

  • (Boolean)


9
10
11
# File 'lib/dbagile/environment/on_error.rb', line 9

def show_backtrace?
  @show_backtrace
end