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

Do not raise an exception if the body is missing from the response #1044

Merged
merged 1 commit into from
Jan 13, 2025

Conversation

andrehjr
Copy link
Contributor

@andrehjr andrehjr commented Jan 11, 2025

If somehow a cassette does not have a string body, VCR shouldn't raise an error.

MethodError (undefined method 'encoding' for nil):

lib/vcr/structs.rb:38:in 'VCR::Normalizers::Body::ClassMethods#try_encode_string'
lib/vcr/structs.rb:24:in 'VCR::Normalizers::Body::ClassMethods#body_from'
lib/vcr/structs.rb:366:in 'VCR::Response.from_hash'
lib/vcr/structs.rb:529:in 'VCR::HTTPInteraction.from_hash'
lib/vcr/cassette.rb:215:in 'block in VCR::Cassette#previously_recorded_interactions'
lib/vcr/cassette.rb:215:in 'Array#map'
lib/vcr/cassette.rb:215:in 'VCR::Cassette#previously_recorded_interactions'
lib/vcr/cassette.rb:107:in 'block in VCR::Cassette#http_interactions'
lib/vcr/cassette.rb:105:in 'Thread::Mutex#synchronize'
lib/vcr/cassette.rb:105:in 'VCR::Cassette#http_interactions'
lib/vcr.rb:346:in 'VCR#http_interactions'
lib/vcr/request_handler.rb:75:in 'VCR::RequestHandler#stubbed_response'
lib/vcr/request_handler.rb:68:in 'VCR::RequestHandler#has_response_stub?'
lib/vcr/request_handler.rb:37:in 'VCR::RequestHandler#request_type'
lib/vcr/request_handler.rb:10:in 'VCR::RequestHandler#handle'
lib/vcr/middleware/faraday.rb:53:in 'VCR::Middleware::Faraday::RequestHandler#handle'
lib/vcr/middleware/faraday.rb:31:in 'VCR::Middleware::Faraday#call'

I didn't understand how the invalid cassette was generated on that issue. That might need a different fix. But anyway, this is nice to have fixed.

Fixes #1042

P.S: Webmock excon specs are failing with excon >= 1.0.0. I fixed it on #1043 Merged!

@andrehjr andrehjr force-pushed the avoid-breaking-if-body-is-missing branch from a898730 to a805d64 Compare January 12, 2025 11:41
@andrehjr andrehjr marked this pull request as ready for review January 12, 2025 11:50
Copy link
Member

@olleolleolle olleolleolle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andrehjr Thank you! Excellent!

@olleolleolle olleolleolle merged commit 5a13948 into vcr:master Jan 13, 2025
41 checks passed
@andrehjr andrehjr deleted the avoid-breaking-if-body-is-missing branch January 13, 2025 12:01
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.

string encoding NoMethod error
2 participants