patchkit-net / patchkit-tools

PatchKit desktop tools.
MIT License
5 stars 1 forks source link

progress_bar.rb:29:in `*': negative argument (ArgumentError) #1

Open blackyale opened 6 years ago

blackyale commented 6 years ago

When executing this command in a Travis CI instance:

./patchkit-tools make-version -s SECRET -a KEY -l "label" -f ../gametest -c "this is the changelog"

I get this error:

patchkit-tools-1.3.0/src/lib/progress_bar.rb:29:in*': negative argument (ArgumentError) from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/lib/progress_bar.rb:29:in print' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/download_version_signatures.rb:71:inblock (2 levels) in execute' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/protocol.rb:429:in call_block' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/protocol.rb:420:in<<' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/protocol.rb:126:in read' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http/response.rb:293:inblock in read_body_0' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http/response.rb:278:in inflater' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http/response.rb:283:inread_body_0' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http/response.rb:204:in read_body' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/download_version_signatures.rb:67:inblock in execute' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/lib/patchkit_api.rb:42:in block (2 levels) in get_response' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:1455:inblock in transport_request' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http/response.rb:165:in reading_body' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:1454:intransport_request' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:1416:in request' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/lib/patchkit_api.rb:40:inblock in get_response' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:877:in start' from /home/travis/.rvm/rubies/ruby-2.4.1/lib/ruby/2.4.0/net/http.rb:608:instart' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/lib/patchkit_api.rb:39:in get_response' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/download_version_signatures.rb:60:inexecute' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/make_version.rb:147:in upload_version_diff' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/make_version.rb:217:inexecute' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/lib/patchkit_tools.rb:14:in execute_tool' from /home/travis/build/AlejandroMoran/GameTest/patchkit-tools-1.3.0/src/lib/tools.rb:85:inexecute' from ./src/lib/bootstrap.rb:38:in <main>'

I needed to comment out some lines inside progressbar library to make this work. This is working fine locally on MacOS. Any idea?

witcher112 commented 6 years ago

Hi @AlejandroMoran! Thank you for reporting this issue ;)

I've checked the code and discovered that the error was caused by wrong assumption that console window is larger than 5 characters.

I've disabled displaying progress bar in those situations - you can check out commit here 2124172cce71454d4c0bba944307d8fd5b5522a3.

I'm leaving this issue open since we will be introducing new output formats (for example JSON) for all of our tools. I think that creating safe output format for CI systems would be a good idea (without fancy progress bars etc.)

Let me know if that fix helps you!

blackyale commented 6 years ago

@witcher112 thanks, I'll check it asap! Anyway, are you planning to release some REST API for your platform in order to get rid of this ruby tool?

For instance: I've been using your API calls (extracted from your ruby tool) in order to get the list of versions (https://panel.patchkit.net/1/apps/TOKEN/versions) but I would like to have some other endpoints like applications list in order to automate most of my deploying process. Thanks for your help!

blackyale commented 6 years ago

@witcher112 Apart from that, I see that your commit is directly into the progressbar library code, this is not supposed to work this way right? or yes? I suppose this third-party libraries were installed with "bundler install" as depicted in the tool documentation, am I wrong? Thanks in advance.

witcher112 commented 6 years ago

@witcher112 Apart from that, I see that your commit is directly into the progressbar library code, this is not supposed to work this way right? or yes? I suppose this third-party libraries were installed with "bundler install" as depicted in the tool documentation, am I wrong? Thanks in advance.

Progress bar is our own implementation shipped inside the tools - it's not a third-party library. So you don't need to worry about it ;)

Anyway, are you planning to release some REST API for your platform in order to get rid of this ruby tool?

Official release of REST API is going to happen in some near future - we've got this on our internal road map. If you want to be notified about this, you can sign up to our mail updates in your profile settings - https://panel.patchkit.net/users/profile

By the way - did the change I made solve your problems :)?

blackyale commented 4 years ago

Hello guys, I've tested this after several time without patchkit and it seems you still have problems with the window size in GitLab.

Error during file upload: undefined methodwinsize' for nil:NilClass`

genail commented 4 years ago

@blackyale By GitLab do you mean running it on GitLab CI?

blackyale commented 4 years ago

@blackyale By GitLab do you mean running it on GitLab CI?

Yes, sorry that I didn't add too much information, I was in hurry. I was using GitLab CI and after a few tries I have it working but I needed to comment code in app/upload_version.rb, the commented code looks as this:

def execute
      check_if_option_exists("secret")
      check_if_option_exists("api_key")
      check_if_option_exists("version")
      check_if_valid_option_value("mode", UPLOAD_MODES)
      check_if_option_file_exists_and_readable("file")
      check_if_option_file_exists_and_readable("diff_summary") if @mode == "diff"

      # Check if the version is draft
      puts "Checking version..."
      app = App.find_by_secret!(@secret)

      version = Version.find_by_id!(app, @version)
      raise "Version must be a draft" unless version.draft?

      puts "Uploading #{@mode}..."

      file_size = File.size(@file)
      # progress_bar = ProgressBar.new(file_size)

      speed_calculator = SpeedCalculator.new

      uploader = S3Uploader.new(@api_key)
      #uploader.on(:progress) do |bytes_sent, bytes_total|
        #speed_calculator.submit(bytes_sent)

        #text = if speed_calculator.ready?
                 #format("Uploading %.2f MB out of %.2f MB (%.2f MB/s)",
                        #bytes_sent / 1024.0**2,
                        #bytes_total / 1024.0**2,
                        #speed_calculator.speed_per_second / 1024.0**2)
               #else
                 #format("Uploading %.2f MB out of %.2f MB",
                        #bytes_sent / 1024.0**2,
                        #bytes_total / 1024.0**2)
               #end

        #progress_bar.print(bytes_sent, text)
      #end

      loop do
        begin
          3.times { puts }
          uploader.upload_file(@file)
          break
        rescue => e
          puts
          puts "Error during file upload: #{e}"
          @retry_count -= 1
          if @retry_count < 0
            if @ask_to_try_again
              if ask_yes_or_no("Try again?", 'y')
                next
              else
                raise CommandLineError, "Couldn't upload the file"
              end
            else
              raise CommandLineError, "Couldn't upload the file"
            end
          end
        end
      end
      upload_id = uploader.upload_id

      #progress_bar.print(file_size, "Upload done", force: true)

      result = case @mode
               when 'content'
                 version.upload_content!(upload_id: upload_id)
               when 'diff'
                 version.upload_diff!(upload_id: upload_id,
                                      diff_summary: File.read(@diff_summary))
               else
                 raise "unknown mode: #{@mode}"
               end

      @processing_job_guid = result[:job_guid]
      # Optionally wait for finish of version processing job
      if @wait_for_job
        puts "Waiting for finish of version processing job..."

        # Display job progress bar
        PatchKitAPI.display_job_progress(@processing_job_guid)
      end
    end

@genail It's basically a comment on the progress bar since it was not able to get columns or rows of GitLab CI. Maybe it worth adding a --no-progress flag.

I used v3.1.1 version of patchkit-tools in a 'ubuntu' docker image.