Class: Commander::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane_core/ui/fastlane_runner.rb

Overview

This class override the run method with our custom stack trace handling In particular we want to distinguish between user_error! and crash! (one with, one without stack trace)

Instance Method Summary collapse

Instance Method Details

#run!Object



6
7
8
9
10
11
12
13
14
15
16
17
18
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
44
45
46
47
48
49
50
51
# File 'lib/fastlane_core/ui/fastlane_runner.rb', line 6

def run!
  require_program :version, :description
  trap('INT') { abort program(:int_message) } if program(:int_message)
  trap('INT') { program(:int_block).call } if program(:int_block)
  global_option('-h', '--help', 'Display help documentation') do
    args = @args - %w(-h --help)
    command(:help).run(*args)
    return
  end
  global_option('-v', '--version', 'Display version information') do
    say version
    return
  end
  parse_global_options
  remove_global_options options, @args

  begin
    run_active_command
  rescue InvalidCommandError => e
    abort "#{e}. Use --help for more information"
  rescue Interrupt => ex
    # We catch it so that the stack trace is hidden by default when using ctrl + c
    if $verbose
      raise ex
    else
      puts "\nCancelled... use --verbose to show the stack trace"
    end
  rescue \
    OptionParser::InvalidOption,
    OptionParser::InvalidArgument,
    OptionParser::MissingArgument => e
    abort e.to_s
  rescue FastlaneCore::Interface::FastlaneError => e # user_error!
    error_message = "\n[!] #{e}".red
    if $verbose # with stack trace
      raise e, "[!] #{e.message}".red, e.backtrace
    else
      abort error_message # without stack trace
    end
  rescue => e # high chance this is actually FastlaneCore::Interface::FastlaneCrash, but can be anything else
    FastlaneCore::CrashReporting.handle_crash(e)
    # From https://stackoverflow.com/a/4789702/445598
    # We do this to make the actual error message red and therefore more visible
    raise e, "[!] #{e.message}".red, e.backtrace
  end
end