<commit_before>require 'fastimage'
require 'timeout'
require 'mini_magick'
require 'curb'

module Badge
  class Runner
    @@retry_attemps = 0
    @@rsvg_enabled = true

    def run(path, options)
      check_tools!
      glob = "/**/*.appiconset/*.{png,PNG}"
      glob = options[:glob] if options[:glob]

      app_icons = Dir.glob("#{path}#{glob}")
      UI.verbose "Verbose active... VERSION: #{Badge::VERSION}".blue
      UI.verbose "Parameters: #{options.values.inspect}".blue

      alpha_channel = false
      if options[:alpha_channel]
        alpha_channel = true
      end

      if app_icons.count > 0
        UI.message "Start adding badges...".green

        shield = nil
        begin
          timeout = Badge.shield_service_timeout
          timeout = options[:shield_service_timeout] if options[:shield_service_timeout]
          Timeout.timeout(timeout.to_i) do
            shield = load_shield(options[:shield]) if options[:shield]
          end
        rescue Timeout::Error
          UI.error "Error loading image from #{Badge.shield_service_name} timeout reached. Use --verbose for more info".red
        rescue Curl::Err::CurlError => error
          response = error.io
          UI.error "Error loading image from #{Badge.shield_service_name} response Error. Use --verbose for more info".red
          UI.verbose response.status if FastlaneCore::Globals.verbose?
        rescue MiniMagick::Invalid<commit_msg>Raise error if custom badge image is not found<commit_after>require 'fastimage'
require 'timeout'
require 'mini_magick'
require 'curb'

module Badge
  class Runner
    @@retry_attemps = 0
    @@rsvg_enabled = true

    def run(path, options)
      check_tools!
      glob = "/**/*.appiconset/*.{png,PNG}"
      glob = options[:glob] if options[:glob]

      app_icons = Dir.glob("#{path}#{glob}")
      UI.verbose "Verbose active... VERSION: #{Badge::VERSION}".blue
      UI.verbose "Parameters: #{options.values.inspect}".blue

      if options[:custom] && !File.exist?(options[:custom])
        UI.error("Could not find custom badge image")
        UI.user_error!("Specify a valid custom badge image path!")
      end

      alpha_channel = false
      if options[:alpha_channel]
        alpha_channel = true
      end

      if app_icons.count > 0
        UI.message "Start adding badges...".green

        shield = nil
        begin
          timeout = Badge.shield_service_timeout
          timeout = options[:shield_service_timeout] if options[:shield_service_timeout]
          Timeout.timeout(timeout.to_i) do
            shield = load_shield(options[:shield]) if options[:shield]
          end
        rescue Timeout::Error
          UI.error "Error loading image from #{Badge.shield_service_name} timeout reached. Use --verbose for more info".red
        rescue Curl::Err::CurlError => error
          response = error.io
          UI.error "Error loading image from #{Badge.shield_service_name} response Error. Use --verbose for more info".red
          UI.verbose response.status if FastlaneCore::Globals.verbose?
        rescue MiniMagick::Invalid
{'fraction_non_alphanumeric': 0.10823909531502424, 'fraction_numerical': 0.0012924071082390954, 'mean_word_length': 2.7256317689530687, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '69922', 'n_tokens_mistral': 911, 'n_tokens_neox': 882, 'n_words': 234}