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

Dynamic analysis stops with "`gsub': invalid byte sequence in US-ASCII (ArgumentError)" #81

Closed
plindelauf opened this issue Jul 16, 2014 · 7 comments

Comments

@plindelauf
Copy link

When I run transpec, the execution stops in the dynamic analysis phase with the following stack trace:

Copying the project for dynamic analysis...
Running dynamic analysis with command "bundle exec rspec"...
/Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/parser-2.1.9/lib/parser/source/buffer.rb:171:in `gsub': invalid byte sequence in US-ASCII (ArgumentError)
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/parser-2.1.9/lib/parser/source/buffer.rb:171:in `raw_source='
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/parser-2.1.9/lib/parser/source/buffer.rb:156:in `source='
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/processed_source.rb:24:in `parse'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/processed_source.rb:19:in `parse_file'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/spec_suite.rb:23:in `block in specs'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/spec_suite.rb:22:in `map'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/spec_suite.rb:22:in `specs'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:87:in `rewrite_specs'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:45:in `block in analyze'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:56:in `in_copied_project'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:44:in `analyze'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/cli.rb:106:in `block in run_dynamic_analysis'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:30:in `block in initialize'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:63:in `block (2 levels) in in_copied_project'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:62:in `chdir'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:62:in `block in in_copied_project'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tmpdir.rb:88:in `mktmpdir'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:60:in `in_copied_project'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/dynamic_analyzer.rb:29:in `initialize'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/cli.rb:104:in `new'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/cli.rb:104:in `run_dynamic_analysis'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/cli.rb:55:in `process'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/cli.rb:38:in `run'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/lib/transpec/cli.rb:19:in `run'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/transpec-2.3.3/bin/transpec:7:in `<main>'

I'm not sure how to proceed...

@yujinakayama
Copy link
Owner

Thanks for the report.

It seems that one of your sources has wrong combination of magic comment and character code. Isn't the error raised when you run rspec?

@plindelauf
Copy link
Author

Hi, thanks for the quick reply.

I have no explicit magic comments set.

Also, I don't see any errors with MRI, but I might be looking in the wrong place: is there a specific command I can run to check?

The only explicit encoding setting I have is in my application.rb, where I have: config.encoding = "utf-8".

@yujinakayama
Copy link
Owner

is there a specific command I can run to check?

Could you try this:

$ git clone https://github.com/yujinakayama/transpec.git
$ cd transpec
$ git checkout issue-81
$ cd /path/to/your-project
$ /path/to/cloned/transpec/bin/transpec

Some DEBUG: Rewriting some/file.rb will be outputted and the last output before the error should indicate the problematic file.

@plindelauf
Copy link
Author

It seems it does not reach that particular BaseRewriter code, since I'm still getting the exact same output as above; the "DEBUG" string is not written:

~/Projecten/RoR/bp(transpec ✔) ../transpec/bin/transpec
Copying the project for dynamic analysis...
Running dynamic analysis with command "bundle exec rspec"...
/Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/parser-2.1.9/lib/parser/source/buffer.rb:171:in `gsub': invalid byte sequence in US-ASCII (ArgumentError)
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/parser-2.1.9/lib/parser/source/buffer.rb:171:in `raw_source='
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/gems/parser-2.1.9/lib/parser/source/buffer.rb:156:in `source='
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/processed_source.rb:24:in `parse'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/processed_source.rb:19:in `parse_file'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/spec_suite.rb:23:in `block in specs'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/spec_suite.rb:22:in `map'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/spec_suite.rb:22:in `specs'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:86:in `rewrite_specs'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:46:in `block in analyze'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:57:in `in_copied_project'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:45:in `analyze'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/cli.rb:74:in `block in run_dynamic_analysis'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:31:in `block in initialize'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:63:in `chdir'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:63:in `block in in_copied_project'
    from /Users/pascal/.rbenv/versions/2.0.0-p451/lib/ruby/2.0.0/tmpdir.rb:88:in `mktmpdir'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:61:in `in_copied_project'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/dynamic_analyzer.rb:30:in `initialize'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/cli.rb:72:in `new'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/cli.rb:72:in `run_dynamic_analysis'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/cli.rb:49:in `process'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/cli.rb:37:in `run'
    from /Users/pascal/Projecten/RoR/transpec/lib/transpec/cli.rb:19:in `run'
    from ../transpec/bin/transpec:7:in `<main>'

@yujinakayama
Copy link
Owner

Ah, you are right. Now it should work. Please git pull in the transpec repo and try again.

@plindelauf
Copy link
Author

Yes! That worked great. Turns out I had a spec file with currency symbols in it. I added the "# encoding: UTF-8" comment to the top of that spec file and then the conversion went fine.

This DEBUG info was very useful for finding the issue. Maybe it is an idea to add it as a command line switch.

Thanks so much of your quick and great help!

@yujinakayama
Copy link
Owner

You're welcome :)

Yeah, maybe I'll add some error handling for this to find the issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants