Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logs command fails: undefined method `each_pair' for #<String:*> if the job has already finished and the logs archived #578

Closed
electrum opened this issue Feb 9, 2018 · 46 comments
Labels

Comments

@electrum
Copy link

@electrum electrum commented Feb 9, 2018

[dphillips@imac:~/src/presto master] travis logs 29248.9
displaying logs for prestodb/presto#29248.9
undefined method `each_pair' for #<String:0x00007fd51a053e70>
Did you mean?  each_char
for a full error report, run travis report --org


[dphillips@imac:~/src/presto master] travis report --org
System
Ruby:                     Ruby 2.5.0-p0
Operating System:         Mac OS X 10.13.3
RubyGems:                 RubyGems 2.7.4

CLI
Version:                  1.8.8
Plugins:                  none
Auto-Completion:          no
Last Version Check:       2018-02-08 18:38:34 -0800

Session
API Endpoint:             https://api.travis-ci.org/
Logged In:                as "electrum"
Verify SSL:               yes
Enterprise:               no

Endpoints
org:                      https://api.travis-ci.org/ (access token, current)

Last Exception
An error occurred running `travis logs --org`:
    NoMethodError: undefined method `each_pair' for #<String:0x00007fd51a053e70>
Did you mean?  each_char
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/session.rb:166:in `get'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/session.rb:319:in `fetch_one'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/session.rb:128:in `reload'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/entity.rb:208:in `load_attribute'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/entity.rb:194:in `relation'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/client/artifact.rb:51:in `body'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:39:in `display_log'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:23:in `run'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/cli/command.rb:198:in `execute'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/lib/travis/cli.rb:64:in `run'
        from /Users/dphillips/homebrew/lib/ruby/gems/2.5.0/gems/travis-1.8.8/bin/travis:18:in `<top (required)>'
        from /Users/dphillips/homebrew/bin/travis:23:in `load'
        from /Users/dphillips/homebrew/bin/travis:23:in `<main>'


For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.
@electrum electrum changed the title logs command fails with undefined method `each_pair' for #<String:*> logs command fails with "undefined method `each_pair' for #<String:*>" Feb 9, 2018
@electrum electrum changed the title logs command fails with "undefined method `each_pair' for #<String:*>" logs command fails with undefined method `each_pair' for #<String:*> Feb 9, 2018
@electrum electrum changed the title logs command fails with undefined method `each_pair' for #<String:*> logs command fails: undefined method `each_pair' for #<String:*> Feb 9, 2018
@eupharis

This comment has been minimized.

Copy link

@eupharis eupharis commented Feb 9, 2018

I'm experiencing this as well.

@adigherman

This comment has been minimized.

Copy link

@adigherman adigherman commented Feb 9, 2018

I'm also seeing this on my end.

@cloudinary-misha

This comment has been minimized.

Copy link

@cloudinary-misha cloudinary-misha commented Feb 18, 2018

Hi I've also experience this issue,
after small research:
issue occurs in client/session.rb => def load
argument data expected to be hash or empty, but string received instead.
def load(data) result = {} (data || {}).each_pair do |key, value| entity = load_entity(key, value) result[key] = entity if entity end result end

@20goto10

This comment has been minimized.

Copy link

@20goto10 20goto10 commented Feb 23, 2018

I was running into this too, and added a patch you can insert in your own code to the "load" method, overriding it. It's a total hack, but it works, which is enough for my purposes (an internal tool).

Note: I posted a solution earlier and then realized it was flawed, but the code below should work.

# There is a bug in the Travis gem (at least as recent as 1.8.8) that causes it to fail loading the log. The below overrides solve the problem.
class Hash
  def to_struct(struct_name)
    Struct.new(struct_name,*keys).new(*values)
  end
end

module Travis
  module Client
    class Session

      def load(data)
        result = {}
        if data.is_a?(String)
          return { log: { attributes: { body: data }}.to_struct('DummyEntity')}.to_struct('DummyLog')
        end
        (data || {}).each_pair do |key, value|
          entity = load_entity(key, value)
          result[key] = entity if entity
        end
        result
      rescue => e
        puts e.message
        puts e.backtrace.join("\n")
      end
    end
  end
end
# End Travis Overrides
@adigherman

This comment has been minimized.

Copy link

@adigherman adigherman commented Feb 27, 2018

Thanks @20goto10, I've added your patch to my local files and ran into:

undefined method 'pending?' for nil:NilClass for a full error report, run travis report --org

NoMethodError: undefined method 'pending?' for nil:NilClass from /usr/local/rvm/gems/ruby-2.1.8/gems/travis-1.8.8/lib/travis/client/artifact.rb:51:inbody'`

I commented unless stream and job.pending? on line 51 (artifact.rb) and now I'm getting the logs again.

Hopefully they'll address this issue soon.

@20goto10

This comment has been minimized.

Copy link

@20goto10 20goto10 commented Feb 27, 2018

@adigherman - Patch is a very kind word! This is solely a useful workaround (hack) I was able to slap together without needing to delve too deep into the rest of the Travis client code.

It looks like that error would only come up if you're hitting the body method with a block for streaming larger logs. So, I'd double-check to make sure you're getting the whole log, and not just one chunk of it, after commenting out that line.

@danielpclark

This comment has been minimized.

Copy link

@danielpclark danielpclark commented Mar 5, 2018

I can verify the same issue comes up with travis logs and travis logs .1

@laanwj

This comment has been minimized.

Copy link

@laanwj laanwj commented Mar 6, 2018

Same error here while using travis logs:

System
Ruby:                     Ruby 2.3.3-p222
Operating System:         Ubuntu 17.10
RubyGems:                 RubyGems 2.5.2.1

CLI
Version:                  1.8.8
Plugins:                  none
Auto-Completion:          no
Last Version Check:       2018-03-06 15:57:09 +0100

Session
API Endpoint:             https://api.travis-ci.org/
Logged In:                as "laanwj"
Verify SSL:               yes
Enterprise:               no

Endpoints
org:                      https://api.travis-ci.org/ (access token, current)

Last Exception
An error occurred running `travis logs --org`:
    NoMethodError: undefined method `each_pair' for #<String:0x00558749d30470>
Did you mean?  each_char
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:166:in `get'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:319:in `fetch_one'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:128:in `reload'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:208:in `load_attribute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:194:in `relation'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/artifact.rb:51:in `body'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:39:in `display_log'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:23:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/command.rb:198:in `execute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli.rb:64:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/bin/travis:18:in `<top (required)>'
        from /usr/local/bin/travis:22:in `load'
        from /usr/local/bin/travis:22:in `<main>'


For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.
dquimper pushed a commit to Liaison-Intl/upgrade_toolbelt that referenced this issue Mar 15, 2018
Daniel Quimper
There is a bug in the Travis gem (at least as recent as 1.8.8) that causes it to fail loading the log. The below overrides solve the problem.

/home/ci/bundle/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load': undefined method `each_pair' for #<String...

Found this workaround here: travis-ci/travis.rb#578 (comment)
dquimper pushed a commit to Liaison-Intl/upgrade_toolbelt that referenced this issue Mar 15, 2018
Daniel Quimper
There is a bug in the Travis gem (at least as recent as 1.8.8) that causes it to fail loading the log. The below overrides solve the problem.

/home/ci/bundle/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load': undefined method `each_pair' for #<String...

Found this workaround here: travis-ci/travis.rb#578 (comment)
dquimper pushed a commit to Liaison-Intl/upgrade_toolbelt that referenced this issue Mar 15, 2018
Daniel Quimper
There is a bug in the Travis gem (at least as recent as 1.8.8) that causes it to fail loading the log. The below overrides solve the problem.

/home/ci/bundle/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load': undefined method `each_pair' for #<String...

Found this workaround here: travis-ci/travis.rb#578 (comment)
@thurt

This comment has been minimized.

Copy link

@thurt thurt commented Mar 30, 2018

I have this issue as well. it seems like it works sometimes and other times not.

System
Ruby:                     Ruby 2.3.3-p222
Operating System:         Linux
RubyGems:                 RubyGems 2.5.2.1

CLI
Version:                  1.8.8
Plugins:                  none
Auto-Completion:          yes
Last Version Check:       2018-03-30 16:57:36 +0000

Session
API Endpoint:             https://api.travis-ci.org/
Logged In:                as "thurt"
Verify SSL:               yes
Enterprise:               no

Endpoints
org:                      https://api.travis-ci.org/ (access token, current)

Last Exception
An error occurred running `travis logs --org`:
    NoMethodError: undefined method `each_pair' for #<String:0x000095b3369298>
Did you mean?  each_char
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:166:in `get'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:319:in `fetch_one'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:128:in `reload'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:208:in `load_attribute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:194:in `relation'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/artifact.rb:51:in `body'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:39:in `display_log'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:23:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/command.rb:198:in `execute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli.rb:64:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/bin/travis:18:in `<top (required)>'
        from /usr/local/bin/travis:22:in `load'
        from /usr/local/bin/travis:22:in `<main>'


For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.
@iriberri

This comment has been minimized.

Copy link

@iriberri iriberri commented Apr 4, 2018

I could reproduce this locally in my macOS machine, and I ran the command with the --debug option to see which requests and at which point this was happening:

$ travis logs --pro --debug
** Loading "/Users/iriberri/.travis/config.yml"
** GET "repos/iriberri/travis-experiments"
**   took 0.79 seconds
** GET "builds/" {:number=>"1994", :repository_id=>xxx}
**   took 0.17 seconds
** GET "jobs/117745214"
**   took 0.18 seconds
displaying logs for iriberri/travis-experiments#1994.1
** GET "logs/117786618"
**   took 0.32 seconds
** GET "https://s3.amazonaws.com/archive.travis-ci.com/jobs/117745214/log.txt?X-Amz-Expires=30&X-Amz-Date=xxxx&X-Amz-Algorithm=xmz-Signature=xxxxxx"
**   took 0.75 seconds
** Storing "/Users/iriberri/.travis/error.log"
undefined method `each_pair' for #<String:0x007fbc8b195e20>
for a full error report, run travis report --pro

I redacted parts of the URL above, but it looks like the CLI is accessing an incorrect/expired log file:

<Error>
  <Code>AccessDenied</Code>
  <Message>Request has expired</Message>
  ...
</Error>

Not sure if this is a red herring here, but posting just in case.

@tback

This comment has been minimized.

Copy link

@tback tback commented Apr 5, 2018

Same here:

travis report --org
System
Ruby:                     Ruby 2.3.3-p222
Operating System:         Debian 9.4
RubyGems:                 RubyGems 2.5.2.1

CLI
Version:                  1.8.8
Plugins:                  none
Auto-Completion:          yes
Last Version Check:       2018-04-05 09:01:12 +0200

Session
API Endpoint:             https://api.travis-ci.org/
Logged In:                as "tback"
Verify SSL:               yes
Enterprise:               no

Endpoints
org:                      https://api.travis-ci.org/ (access token, current)

Last Exception
An error occurred running `travis logs --org`:
    NoMethodError: undefined method `each_pair' for #<String:0x00563522dfb850>
Did you mean?  each_char
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:139:in `load'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:166:in `get'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:319:in `fetch_one'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb:128:in `reload'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:208:in `load_attribute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:194:in `relation'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/artifact.rb:51:in `body'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:39:in `display_log'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/logs.rb:23:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli/command.rb:198:in `execute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/cli.rb:64:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.8/bin/travis:18:in `<top (required)>'
        from /usr/local/bin/travis:22:in `load'
        from /usr/local/bin/travis:22:in `<main>'
@tback

This comment has been minimized.

Copy link

@tback tback commented Apr 10, 2018

it'd be great to get a fix or maybe workaround from travis

@drhumlen

This comment has been minimized.

Copy link

@drhumlen drhumlen commented Apr 10, 2018

Same issue...

@tback

This comment has been minimized.

Copy link

@tback tback commented Apr 10, 2018

I looked through this issue again after venting earlier this morning.

This is not a solution in itself, it's just the piece that I didn't pick up while skimming through this issue and being unfamiliar with ruby.

The workaround is to patch client/session.rb yourself as suggested and described in #578 (comment) .

If you don't know where to find the file run travis report --org. It'll show you the stacktrace and a path like the following:

/var/lib/gems/2.3.0/gems/travis-1.8.8/lib/travis/client/session.rb

Then you add the class Hash at the top of the file and the three lines to the load method from from the comment above:

    if data.is_a?(String)
      return { log: { attributes: { body: data }}.to_struct('DummyEntity')}.to_struct('DummyLog')
    end
@leusonmario

This comment has been minimized.

Copy link

@leusonmario leusonmario commented Apr 12, 2018

I also have the same problem.

@leusonmario

This comment has been minimized.

Copy link

@leusonmario leusonmario commented May 3, 2018

Any update?

@jwiegley

This comment has been minimized.

Copy link

@jwiegley jwiegley commented May 6, 2018

Would also love to see a 1.8.9 release to fix.

@leusonmario

This comment has been minimized.

Copy link

@leusonmario leusonmario commented May 7, 2018

@tback I tried your fix, but I got the following problem: artifact.rb:51:in body': undefined method pending?' for nil:NilClass (NoMethodError)

Would you have any idea about how to fix this new error?

@adigherman

This comment has been minimized.

Copy link

@adigherman adigherman commented May 7, 2018

@leusonmario did you try #578 (comment)?

@leusonmario

This comment has been minimized.

Copy link

@leusonmario leusonmario commented May 8, 2018

@adigherman Thanks. Your solution fixed the problem!

textarcana added a commit to textarcana/travis.rb that referenced this issue May 30, 2018
As described here: travis-ci#578 (comment)
@emma-sax4 emma-sax4 mentioned this issue Jun 15, 2018
0 of 1 task complete
@woky

This comment has been minimized.

Copy link

@woky woky commented Aug 13, 2018

Do you know which was the last version with logs working or whether it depends on environment. In other words, does anyone use logs with recent version without patching? I'm just curious where the bug originates from.

@eneko

This comment has been minimized.

Copy link

@eneko eneko commented Sep 4, 2018

This issue seems to still happen with Ruby 2.5.1 and travis gem 1.8.9.

$ travis logs
displaying logs for {redacted}#2560.1
undefined method `each_pair' for #<String:0x00007faea91cc960>
Did you mean?  each_char
for a full error report, run travis report --pro

$ travis report --pro
System
Ruby:                     Ruby 2.5.1-p57
Operating System:         Mac OS X 10.13.6
RubyGems:                 RubyGems 2.7.6

CLI
Version:                  1.8.9
Plugins:                  none
Auto-Completion:          no
Last Version Check:       2018-09-04 09:50:21 -0700

Session
API Endpoint:             https://api.travis-ci.com/
Logged In:                as "eneko"
Verify SSL:               yes
Enterprise:               no

Endpoints
com:                      https://api.travis-ci.com/ (access token, current)
org:                      https://api.travis-ci.org/ (access token)

Last Exception
An error occurred running `travis logs --pro`:
    NoMethodError: undefined method `each_pair' for #<String:0x00007f7f40a22ff8>
Did you mean?  each_char
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/session.rb:139:in `load'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/session.rb:166:in `get'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/session.rb:319:in `fetch_one'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/session.rb:128:in `reload'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/entity.rb:208:in `load_attribute'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/entity.rb:194:in `relation'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/artifact.rb:51:in `body'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/cli/logs.rb:39:in `display_log'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/cli/logs.rb:23:in `run'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/cli/command.rb:198:in `execute'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/cli.rb:64:in `run'
        from /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/bin/travis:18:in `<top (required)>'
        from /usr/local/bin/travis:23:in `load'
        from /usr/local/bin/travis:23:in `<main>'

For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.
@trinitronx

This comment has been minimized.

Copy link

@trinitronx trinitronx commented Oct 1, 2018

Testing patch in textarcana#1 on travis gem 1.8.9 with Ruby 2.5.1 still results in same error & stacktrace posted by @eneko.

Function that fails is the line calling each_pair here:

 # /usr/local/lib/ruby/gems/2.5.0/gems/travis-1.8.9/lib/travis/client/session.rb:139:in `load'
  def load(data)
    result = {}
    (data || {}).each_pair do |key, value|
      entity      = load_entity(key, value)
      result[key] = entity if entity
    end
    result
  end

There is a String in one of these data objects which looks like the log output. This can be observed if you add some print lines right before this to print things out:

  def load(data)
    result = {}
    require 'pp'
    pp data.class
    pp data
    (data || {}).each_pair do |key, value|
      entity      = load_entity(key, value)
      result[key] = entity if entity
    end
    result
  end
Hash
[...SNIP...]
Hash
[...SNIP...]
displaying logs for username/reponame#NN.X
String
"travis_fold:start:step_upload_script\r\e[0K\e[33;1mUploading script\e[0m\r\n" +
"travis_fold:end:step_upload_script\r\e[0Ktravis_fold:start:worker_info\r\e[0K\e[33;1mWorker information\e[0m\n" +
"hostname: d516ec12-a65d-4454-ba88-daba63f36213@1.production-1-worker-org-gce-n8qm\n" +
"version: v4.2.0 https://github.com/travis-ci/worker/tree/7d17a81b8afc19da6842f1153f37371e859f4ccd\n" +
"instance: travis-job-1620ef03-61f5-425f-bc2d-edb70fd33148 travis-ci-garnet-trusty-1513287054-2ffda03 (via amqp)\n" +
"startup: 2m3.167309656s\n" +
"travis_fold:end:worker_info\r\e[0Ktravis_fold:start:system_info\r\e[0K\e[33;1mBuild system information\e[0m\r\n" +
"Build language: python\r\n" +
"Build group: edge\r\n" +
"Build dist: trusty\r\n" +
"Build id: 435742078\r\n" +
"Job id: 435742080\r\n" +
"Runtime kernel version: 4.4.0-104-generic\r\n" +
"travis-build version: e1590b459\r\n" +
"\e[34m\e[1mBuild image provisioning date and time\e[0m\r\n" +
"Thu Dec 14 21:58:09 UTC 2017\r\n" +
"\e[34m\e[1mOperating System Details\e[0m\r\n" +
"Distributor ID:\tUbuntu\r\n" +
"Description:\tUbuntu 14.04.5 LTS\r\n" +
"Release:\t14.04\r\n" +
"Codename:\ttrusty\r\n" +
[...SNIP...]

This object is a long ruby string with "text" + " more text " + ... representing the build log output. Assumptions based on this are that at some point maybe this was a type supporting .each_pair, maybe this code was different, or Travis API output changed?

@ChristopherHackett

This comment has been minimized.

Copy link

@ChristopherHackett ChristopherHackett commented Oct 30, 2018

Same issue here :(

Maybe I did it wrong but I also could not get the suggested "patch" to work

System
Ruby:                     Ruby 2.1.3-p242
Operating System:         Mac OS X 10.12.6
RubyGems:                 RubyGems 2.2.2

CLI
Version:                  1.8.9
Plugins:                  none
Auto-Completion:          no
Last Version Check:       2018-10-30 12:16:51 +0000

Session
API Endpoint:             https://api.travis-ci.com/
Logged In:                as "ChristopherHackett"
Verify SSL:               yes
Enterprise:               no

Endpoints
com:                      https://api.travis-ci.com/ (access token, current)
org:                      https://api.travis-ci.org/ (access token)

Last Exception
An error occurred running 'travis logs --pro':
    NoMethodError: undefined method 'each_pair' for #<String:0x007fa160bef808>
@BanzaiMan BanzaiMan added bug api labels Nov 3, 2018
@RaVbaker

This comment has been minimized.

Copy link

@RaVbaker RaVbaker commented Nov 27, 2018

I also experience same issue Ruby: 2.5.1 and travis gem version 1.8.9. :/ Any ETA for a fix ?

This is error Which I got:

$ travis report --pro
System
Ruby:                     Ruby 2.5.1-p57
Operating System:         Mac OS X 10.14.1
RubyGems:                 RubyGems 2.7.6

CLI
Version:                  1.8.9
Plugins:                  none
Auto-Completion:          yes
Last Version Check:       2018-11-27 14:05:54 +0100

Session
API Endpoint:             https://api.travis-ci.com/
Logged In:                as "RaVbaker"
Verify SSL:               yes
Enterprise:               no

Endpoints
org:                      https://api.travis-ci.org/ ()
com:                      https://api.travis-ci.com/ (access token, current)

Last Exception
An error occurred running `travis logs --pro`:
    NoMethodError: undefined method `each_pair' for #<String:0x00007fce1534e690>
Did you mean?  each_char
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/session.rb:139:in `load'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/session.rb:166:in `get'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/session.rb:319:in `fetch_one'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/session.rb:128:in `reload'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/entity.rb:208:in `load_attribute'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/entity.rb:194:in `relation'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/client/artifact.rb:51:in `body'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/cli/logs.rb:39:in `display_log'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/cli/logs.rb:23:in `run'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/cli/command.rb:198:in `execute'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/lib/travis/cli.rb:64:in `run'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/gems/travis-1.8.9/bin/travis:18:in `<top (required)>'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/bin/travis:23:in `load'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/bin/travis:23:in `<main>'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/bin/ruby_executable_hooks:15:in `eval'
        from /Users/ravbaker/.rvm/gems/ruby-2.5.1@x/bin/ruby_executable_hooks:15:in `<main>'


For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.

And the data payload that is there looks like this:

"travis_fold:start:worker_info\r\e[0K\e[33;1mWorker information\e[0m\nhostname: 0d6710a5-1caa-494a-92d0-133f69bc0c3f@1.production-3-worker-com-gce-7pxp\n...

instead of being a hash

@BanzaiMan

This comment has been minimized.

Copy link
Member

@BanzaiMan BanzaiMan commented Nov 29, 2018

Sorry for the delay, everyone.

@textarcana Do you mind opening a PR with your patch? I somehow missed it completely.

@OGKevin

This comment has been minimized.

Copy link

@OGKevin OGKevin commented Dec 23, 2018

Any update? I'm also experiencing this :(

mtsmfm added a commit to mtsmfm/travis.rb that referenced this issue Jan 6, 2019
I can't find any document about the previous format for `/logs/:id` but I guess it was like this:

```json
{log: {id: 123, body: 'travis_fold:start:worker_info...'}}
```
mtsmfm added a commit to mtsmfm/travis.rb that referenced this issue Jan 6, 2019
@poppyschmo

This comment has been minimized.

Copy link

@poppyschmo poppyschmo commented Jan 11, 2019

Seems there's some recent PR activity.

Been making do with this ugliness, but hopefully not for much longer:

# Scrape 307 Temporary Redirect response for "Location" header field
# Drop non-printables, less ANSI \e and carriage (Tools::SafeString.colorized)
# "$@" means "the" "rest" (opts/args ...)
curl "$(travis logs --debug-http "$@" | grep ^Location: | cut -d \" -f 2)" | \
    sed 's/[^[:print:]\x1b\r]//g'
@hotdog2201

This comment has been minimized.

Copy link

@hotdog2201 hotdog2201 commented Mar 21, 2019

Any progress on this? Still getting this when trying to do any travis command such as whoami or encrypt. "undefined method `each_pair' for #String:0x00000001058240"

@markgaensicke

This comment has been minimized.

Copy link

@markgaensicke markgaensicke commented Sep 23, 2019

Any progress on this?

@adumont

This comment has been minimized.

Copy link

@adumont adumont commented Sep 29, 2019

Same issue here

$ travis report --org
System
Ruby: Ruby 2.3.1-p112
Operating System: Ubuntu 16.04
RubyGems: RubyGems 2.5.2.1

CLI
Version: 1.8.10
Plugins: none
Auto-Completion: yes
Last Version Check: 2019-09-29 20:48:06 +0200

Session
API Endpoint: https://api.travis-ci.org/
Logged In: as "adumont"
Verify SSL: yes
Enterprise: no

Endpoints
org: https://api.travis-ci.org/ (access token, current)

Last Exception
An error occurred running travis logs --org:

    NoMethodError: undefined method `each_pair' for #<String:0x000000022ff088>
Did you mean?  each_char
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/session.rb:139:in `load'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/session.rb:166:in `get'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/session.rb:325:in `fetch_one'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/session.rb:128:in `reload'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/entity.rb:208:in `load_attribute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/entity.rb:54:in `block (2 levels) in attributes'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/entity.rb:194:in `relation'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/entity.rb:71:in `block (2 levels) in has'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/client/artifact.rb:51:in `body'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/cli/logs.rb:39:in `display_log'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/cli/logs.rb:23:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/cli/command.rb:198:in `execute'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/lib/travis/cli.rb:64:in `run'
        from /var/lib/gems/2.3.0/gems/travis-1.8.10/bin/travis:18:in `<top (required)>'
        from /usr/local/bin/travis:23:in `load'
        from /usr/local/bin/travis:23:in `<main>'

For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.

@cryptid11

This comment has been minimized.

Copy link

@cryptid11 cryptid11 commented Oct 28, 2019

shouldnt this having some priority at this point ? :/ btw also for me the @textarcana patch doesnt work! im gonna use @poppyschmo art XD (thanks)

@ashutosh108

This comment has been minimized.

Copy link

@ashutosh108 ashutosh108 commented Jan 18, 2020

It's 2020, but the same bug is still there e.g. for travis logs:

travis report --com
System
Ruby:                     Ruby 2.7.0-p0
Operating System:         Windows
RubyGems:                 RubyGems 3.1.2

CLI
Version:                  1.8.10
Plugins:                  none
Auto-Completion:          yes
Last Version Check:       2020-01-18 11:50:05 +0200

Session
API Endpoint:             https://api.travis-ci.com/
Logged In:                as "ashutosh108"
Verify SSL:               yes
Enterprise:               no

Endpoints
org:                      https://api.travis-ci.org/ ()
com:                      https://api.travis-ci.com/ (access token, default, current)

Last Exception
An error occurred running `travis logs --pro`:
    NoMethodError: undefined method `each_pair' for #<String:0x00000000063bf708>
Did you mean?  each_char
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/session.rb:139:in `load'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/session.rb:166:in `get'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/session.rb:325:in `fetch_one'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/session.rb:128:in `reload'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/entity.rb:208:in `load_attribute'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/entity.rb:54:in `block (2 levels)
in attributes'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/entity.rb:194:in `relation'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/entity.rb:71:in `block (2 levels)
in has'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/client/artifact.rb:51:in `body'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/cli/logs.rb:39:in `display_log'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/cli/logs.rb:23:in `run'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/cli/command.rb:198:in `execute'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/lib/travis/cli.rb:64:in `run'
        from C:/tools/ruby27/lib/ruby/gems/2.7.0/gems/travis-1.8.10/bin/travis:18:in `<top (required)>'
        from C:/tools/ruby27/bin/travis:23:in `load'
        from C:/tools/ruby27/bin/travis:23:in `<main>'

For issues with the command line tool, please visit https://github.com/travis-ci/travis.rb/issues.
For Travis CI in general, go to https://github.com/travis-ci/travis-ci/issues or email support@travis-ci.com.
@kalbert312

This comment has been minimized.

Copy link

@kalbert312 kalbert312 commented Mar 6, 2020

I debugged this today since I'm trying to login to a github enterprise server. It looks like the string is an html error page from the GHE api. The GHE I was trying to login with a token uses SSO and I was seeing a redirect to the SSO page in the debug output of travis login -X --github-token=TOKEN along with a 401 response. It never successfully logged in so user id is nil so all the request urls requiring user id are incorrect.

EDIT: Figured out my problem. I wasn't adding /api to the end of my endpoint, so the login was failing producing an html error page. That html error page was the string that was causing this error.

@JunzhouLiu

This comment has been minimized.

Copy link

@JunzhouLiu JunzhouLiu commented Mar 6, 2020

emmmm

System
Ruby:                     Ruby 2.5.1-p57
Operating System:         Ubuntu 18.04
RubyGems:                 RubyGems 2.7.6

CLI
Version:                  1.8.11
Plugins:                  none
Auto-Completion:          no
Last Version Check:       2020-03-07 06:02:04 +0800

Session
API Endpoint:             https://api.travis-ci.com/
Logged In:                as "JunzhouLiu"
Verify SSL:               yes
Enterprise:               no

Endpoints
com:                      https://api.travis-ci.com/ (access token, current)
org:                      https://api.travis-ci.org/ (access token)

Last Exception
An error occurred running `travis encrypt-file --pro`:
    ArgumentError: wrong number of arguments (given 1, expected 2)
        from /var/lib/gems/2.5.0/gems/travis-1.8.11/lib/travis/cli/encrypt_file.rb:79:in `env_name'
        from /var/lib/gems/2.5.0/gems/travis-1.8.11/lib/travis/cli/encrypt_file.rb:70:in `decrypt_command'
        from /var/lib/gems/2.5.0/gems/travis-1.8.11/lib/travis/cli/encrypt_file.rb:42:in `run'
        from /var/lib/gems/2.5.0/gems/travis-1.8.11/lib/travis/cli/command.rb:198:in `execute'
        from /var/lib/gems/2.5.0/gems/travis-1.8.11/lib/travis/cli.rb:64:in `run'
        from /var/lib/gems/2.5.0/gems/travis-1.8.11/bin/travis:18:in `<top (required)>'
        from /usr/local/bin/travis:23:in `load'

@BanzaiMan

This comment has been minimized.

Copy link
Member

@BanzaiMan BanzaiMan commented Mar 6, 2020

@JunzhouLiu That's not the same issue. That one is fixed by #715 (and will be released soon).

@JunzhouLiu

This comment has been minimized.

Copy link

@JunzhouLiu JunzhouLiu commented Mar 6, 2020

@JunzhouLiu That's not the same issue. That one is fixed by #715 (and will be released soon).

okey, thank you for your reply !

@BanzaiMan BanzaiMan changed the title logs command fails: undefined method `each_pair' for #<String:*> logs command fails: undefined method `each_pair' for #<String:*> if the job has already finished and the logs archived Mar 10, 2020
@BanzaiMan

This comment has been minimized.

Copy link
Member

@BanzaiMan BanzaiMan commented Mar 10, 2020

Hello, everyone. Please test 1.8.12.rc1 for a possible fix to this issue. Thank you!

#718 (comment)

I think it's better to fix API, after all; while the gem ↑ should do the job, we'll have to hold off on releasing that.

@BanzaiMan

This comment has been minimized.

Copy link
Member

@BanzaiMan BanzaiMan commented Mar 18, 2020

It should work now without updating your client.

$ travis logs -r BanzaiMan/travis_production_test
displaying logs for BanzaiMan/travis_production_test#5226.1
Worker information
hostname: b65b0874-2c3e-411b-8729-b7699aea9fcf@1.worker-org-676f4fdd9b-gkwdb.gce-production-2

Skipping a deployment with the script provider because the current build is a pull request.

Done. Your build exited with 0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.