Skip to content

Only String accepted for source (ArgumentError) #56

Closed

Description

@ryanjm

I've run into this twice now, and I'm sorry, but I don't know what's tripping it up.

I'm using guard to run my tests / simplecov.

If it runs with this code:

def following_all
  ...
  all.map! do |a|
    # Return array
    if a.class == MyClass
      ... do something
    else
      ... do something else
    end
  end
  all.flatten!
end

It will be fine. But if I take out that the line with the comment (the comment doesn't matter, the extra line does) then it will crash.

/Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:25:in `initialize': Only String accepted for source (ArgumentError)
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:66:in `new'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:66:in `block in lines'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:65:in `each'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:65:in `each_with_index'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:65:in `lines'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-0.4.2/lib/simplecov/source_file.rb:91:in `missed_lines'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-html-0.4.5/lib/simplecov-html.rb:80:in `block in lines_missed'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-html-0.4.5/lib/simplecov-html.rb:80:in `map'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-html-0.4.5/lib/simplecov-html.rb:80:in `lines_missed'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-html-0.4.5/lib/simplecov-html.rb:70:in `lines_of_code'
    from /Users/ryanjm/.rvm/gems/ruby-1.9.2-head/gems/simplecov-html-0.4.5/lib/simplecov-html.rb:63:in `coverage'
    from (erb):4:in `formatted_file_list'
    ....

Any idea what is tripping this issue?

Activity

  1. jherdman commented on Jul 13, 2011

    @jherdman

    Bump! I'm seeing this quite regularly too.

  2. ryanjm commented on Jul 22, 2011

    @ryanjm
    Author

    Bump again? This is happening a lot. Is there something I can do to reduce the probability of this happening? I prefer not having extra spaces between all of my lines of code.

  3. goneflyin commented on Jul 27, 2011

    @goneflyin
    Contributor

    I wouldn't be certain it's as directly related to the above code as it may be thought.

    Our CI build hit this exception after running specs on a Rails 3 project -- but we've got

        @rooms[0].rooms.each do |room|
          data << <<-eos
    
          eos
        end

    More than that, however, is how we "fixed" it. I checked in a different change (eliminated a HAML warning by changing)

    - form_for
    

    to:
    = form_for

    and then our CI build re-ran the tests, and the simplecov exception did not occur.

    (apologies for the inconsistent syntax highlighting and blocking, can't quite get GFM to render it correctly)

    At this time I'm not sure exactly what triggered the original problem, or how the rebuild fixed it, but there was no difference between the two builds that related to a ruby code structure as illustrated above.

  4. ryanjm commented on Jul 27, 2011

    @ryanjm
    Author

    Interesting. I never get it for views. Only ever for blocks of code in my models.

  5. goneflyin commented on Jul 28, 2011

    @goneflyin
    Contributor

    Sorry -- to be clear, my point was that we have code (the example above was from a controller) that resembles the example in the description of this issue. The view example was to point out that checking in only a change to a view where we change the hyphen(-) to an equals-sign (=) resulted in the CI build working, and the simplecov exception no longer occurred.

  6. goneflyin commented on Jul 28, 2011

    @goneflyin
    Contributor

    Another observation I made yesterday, throwing a few debug strings into simplecov to understand the nature of the problem, is that the underlying problem may have something to do with the Coverage library in Ruby 1.9.

    First -- the problem became (effectively) non-deterministic for me. I had reproduced the exception above via running my tests via rake. While tweaking only the source_file.rb file within the simplecov gem directory, the defect suddenly stopped happening and would no longer occur during this test run.

    Second -- the unique situation causing the exception to be thrown seems to be due to the Coverage library returning an extra, non-existent line of data for a source file.

    The exception is thrown from here (my slight hack to the exception message is included, so it won't match the released source perfectly):

          def initialize(src, line_number, coverage)
            raise ArgumentError, "Only String accepted for source (line_number: #{line_number})" unless src.kind_of?(String)
            raise ArgumentError, "Only Fixnum accepted for line_number" unless line_number.kind_of?(Fixnum)
            raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil?
            @src, @line_number, @coverage = src, line_number, coverage
          end

    In my case, whenever I get this exception thrown, the line_number is one more than the number of lines in the file. As a result, the src (intended to be the line of source code extracted from the file) is nil rather than the empty string.

    I'll look at checking for this condition in the calling loop and try to display a warning and avoid triggering the exception. If I can get a decent patch done, I'll submit a pull request.

  7. added a commit that references this issue on Aug 1, 2011
  8. colszowka commented on Aug 1, 2011

    @colszowka
    Collaborator

    Ok, thanks to @goneflyin this should be fixed in the next release / right now on master. Please let me know should this problem persist!

  9. added theissue type on May 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions