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

Fix cache with non UTF-8 offense message #7119

Merged
merged 1 commit into from Jun 11, 2019
Merged

Conversation

pocke
Copy link
Collaborator

@pocke pocke commented Jun 10, 2019

Problem

If offense message's encoding is not UTF-8, the cache system raises an error.

Offense message can be an ASCII-8BIT if the offense message is constructed with ASCII-8BIT source code.
For example, YodCondition cop's message will be it.

test.rb

# encoding: ascii-8bit

x = ''

if "あ" == x
end
$ rubocop --only YodaCondition
"\xE3" from ASCII-8BIT to UTF-8
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/json/common.rb:224:in `encode'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/json/common.rb:224:in `generate'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/json/common.rb:224:in `generate'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/json/common.rb:394:in `dump'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/cached_data.rb:17:in `to_json'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/result_cache.rb:116:in `block in save'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/result_cache.rb:115:in `open'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/result_cache.rb:115:in `save'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:211:in `save_in_cache'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:143:in `file_offense_cache'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:122:in `file_offenses'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:110:in `process_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:87:in `block in each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:86:in `each'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:86:in `reduce'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:86:in `each_inspected_file'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:73:in `inspect_files'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/runner.rb:39:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/cli.rb:210:in `execute_runner'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/cli.rb:80:in `execute_runners'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/lib/rubocop/cli.rb:51:in `run'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/exe/rubocop:13:in `block in <top (required)>'
/home/pocke/.rbenv/versions/trunk/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/home/pocke/.rbenv/versions/trunk/lib/ruby/gems/2.7.0/gems/rubocop-0.71.0/exe/rubocop:12:in `<top (required)>'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `load'
/home/pocke/.rbenv/versions/trunk/bin/rubocop:23:in `<main>'
Inspecting 1 file


0 files inspected, no offenses detected

This change will fix the problem.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic
Copy link
Member

koic commented Jun 11, 2019

👍

@pocke pocke deleted the encoding-cache branch June 11, 2019 01:24
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

Successfully merging this pull request may close these issues.

None yet

2 participants