-
Notifications
You must be signed in to change notification settings - Fork 52
Fix content(raw=>1) dies when there is no response #397
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
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a bug where calling content(raw=>1)
on a WWW::Mechanize object would die when there is no response object, addressing issue #384.
- Added null check for response object before calling content() method
- Added test coverage to verify raw content handling when no response exists
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
lib/WWW/Mechanize.pm | Added safety check to prevent calling content() on undefined response object |
t/content.t | Added test case to verify raw content returns undef when no response exists |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
$content = $res->content() if $res; | ||
} | ||
elsif ( delete $params{decoded_by_headers} ) { | ||
$content = $self->response()->decoded_content( charset => 'none' ); |
Copilot
AI
Oct 9, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to the raw content case, this line could also die if response()
returns undef. The same null check should be applied here for consistency.
$content = $self->response()->decoded_content( charset => 'none' ); | |
my $res = $self->response(); | |
$content = $res->decoded_content( charset => 'none' ) if $res; |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot makes a good point.
It seems to me the whole problem follows when user requests for content before any remote http call has been made.
Is there any way to prevent that? Or do we even want to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any way to prevent that? Or do we even want to?
I think this is a good start. We can protect the user from themselves without introducing new types of errors. Even with really innocent looking changes, often someone will appear after a subsequent release to let us know that our fix has broken their code. So, it's good to be conservative here. I think this particular case is worth fixing, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then we are done and ready for merging?
#384