Skip to content
This repository has been archived by the owner on Nov 30, 2024. It is now read-only.

Prevent invalid encoding for files blowing up Source.from_file #364

Closed
wants to merge 2 commits into from

Conversation

JonRowe
Copy link
Member

@JonRowe JonRowe commented Feb 5, 2019

From rspec/rspec#102 an invalid encoding combination in a file can cause an error which stops RSpec from running and highlighting the correct cause:

Traceback (most recent call last):
	28: from bin/ruby_executable_hooks:24:in `<main>'
	27: from bin/ruby_executable_hooks:24:in `eval'
	26: from bin/rspec:23:in `<main>'
	25: from bin/rspec:23:in `load'
	24: from gems/rspec-core-3.8.0/exe/rspec:4:in `<top (required)>'
	23: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:45:in `invoke'
	22: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:71:in `run'
	21: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:86:in `run'
	20: from gems/rspec-core-3.8.0/lib/rspec/core/runner.rb:98:in `setup'
	19: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1558:in `load_spec_files'
	18: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1558:in `each'
	17: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:1560:in `block in load_spec_files'
	16: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:2033:in `load_file_handling_errors'
	15: from gems/rspec-core-3.8.0/lib/rspec/core/configuration.rb:2037:in `rescue in load_file_handling_errors'
	14: from gems/rspec-core-3.8.0/lib/rspec/core/reporter.rb:161:in `notify_non_example_exception'
	13: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:78:in `fully_formatted'
	12: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:86:in `fully_formatted_lines'
	11: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:240:in `formatted_message_and_backtrace'
	10: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:34:in `colorized_message_lines'
	 9: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:149:in `failure_lines'
	 8: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:149:in `tap'
	 7: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:150:in `block in failure_lines'
	 6: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:163:in `failure_slash_error_lines'
	 5: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/exception_presenter.rb:218:in `read_failed_lines'
	 4: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/snippet_extractor.rb:30:in `extract_expression_lines_at'
	 3: from gems/rspec-core-3.8.0/lib/rspec/core/formatters/snippet_extractor.rb:18:in `source_from_file'
	 2: from gems/rspec-core-3.8.0/lib/rspec/core/world.rb:150:in `source_from_file'
	 1: from gems/rspec-support-3.8.0/lib/rspec/support/source.rb:12:in `from_file'
gems/rspec-support-3.8.0/lib/rspec/support/source.rb:12:in `read': U+043F from UTF-8 to ASCII-8BIT (Encoding::UndefinedConversionError)

After this PR:

An error occurred while loading ./spec/support/source_spec.broken_example.
Failure/Error: Unable to find matching line in ./spec/support/source_spec.broken_example

NameError:
  uninitialized constant UndeclaredModule

@JonRowe JonRowe force-pushed the invalid-encoding-source-from-file-fix branch from b5f1cda to 8bc3b72 Compare February 5, 2019 20:19
@JonRowe JonRowe force-pushed the invalid-encoding-source-from-file-fix branch from 8bc3b72 to 7aa2de0 Compare June 12, 2019 20:51
@JonRowe JonRowe changed the base branch from master to main August 2, 2020 01:55
@JonRowe JonRowe force-pushed the invalid-encoding-source-from-file-fix branch 9 times, most recently from f5111f2 to 6c09bad Compare November 29, 2024 09:39
@JonRowe JonRowe force-pushed the invalid-encoding-source-from-file-fix branch from 6c09bad to adafd70 Compare November 29, 2024 19:12
@JonRowe JonRowe closed this Nov 29, 2024
@JonRowe JonRowe deleted the invalid-encoding-source-from-file-fix branch November 29, 2024 19:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant