Skip to content

Comments

Prevent assigning error to $this->usage#40

Closed
kienstra wants to merge 4 commits intodevelopfrom
update/address-fatal-error-activation
Closed

Prevent assigning error to $this->usage#40
kienstra wants to merge 4 commits intodevelopfrom
update/address-fatal-error-activation

Conversation

@kienstra
Copy link
Contributor

There was a fatal error reported on activation:

An error of type E_ERROR was caused in line 340 of the file /path/to/
wp-content/plugins/cloudinary_wordpress_v2/php/sync/class-push-sync.php. Error
message: Uncaught Error: Cannot use object of type WP_Error as array in
/path/to/wp-content/plugins/cloudinary_wordpress_v2/php/sync/
class-push-sync.php:340

if ( $file_size > $this->plugin->components['connect']->usage[ $max_size ] ) {

I couldn't reproduce that, with the same versions as reported in the bug:
PHP 7.4
WP Core 5.3.2
Foodoholic theme

But this PR addresses one possible cause of the error.

It might be possible that $this->plugin->components['connect']->usage is a WP_Error, causing this fatal error.

It looks like the code anticipates $stats being a WP_Error:

if ( ! is_wp_error( $stats ) && ! empty( $stats['media_limits'] ) ) {

If so, it will be assigned to $this->plugin->components['connect']->usage:

...possibly causing the error the user reported.

Still, I can't reproduce the error that was reported. So it's only a guess that this might fix it.

This could have been a cause of the error
on activating the plugin,
though I couldn't reproduct it, even
with the same PHP and WP versions and theme.
But it looks like the code anticipates $stats
possibly being an error.
In that case, it probably shouldn't be assigned to
$this->usage.
@kienstra
Copy link
Contributor Author

Request For Review

Hi @dugajean,
Thanks a lot for reviewing #39. Could you please review this?

Thanks, Dugi!

@kienstra kienstra requested a review from parabrola January 30, 2020 17:45
This should still not allow this
to be stored.
This can still be set as $this->usage,
it should just exit.
@kienstra
Copy link
Contributor Author

Sorry, not planning on making any more commits before review 😄

Comment on lines +285 to +290

if ( is_wp_error( $stats ) ) {
return;
}

if ( ! empty( $stats['media_limits'] ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it might be a better idea to set some defaults before returning if there's a WP_Error since there are 5 uses of its keys around the plugin, which might cause undefined index errors.

  • See class-media.php at line 1079-1080
  • See class-push-sync.php at line 340-341
  • See class-upload-sync.php at line 120

What do you think @kienstra ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uf, good point

@kienstra
Copy link
Contributor Author

kienstra commented Jan 30, 2020

Closing

This PR is only a guess at one way the fatal error reported could have happened. Since I can't reproduce the issue, I don't think it makes sense to continue.

If there really was a WP_Error from calling the API:

return new \WP_Error( $request['response']['code'], $result['error']['message'] );

...then there would need to be better UI handling for this. The user would probably need to know that there was some kind of error in order to try again.

Simply setting 'max_image_size' to a default like 0 or PHP_INT_MAX doesn't seem fair, as it might not have been their fault.

I don't think we can 'fix' something that's not reproducible.

@kienstra kienstra closed this Jan 30, 2020
@const-cloudinary
Copy link
Contributor

@kienstra , I can reproduce this, we have an environment that fails with this issue.

@kienstra
Copy link
Contributor Author

kienstra commented Feb 3, 2020

@const-cloudinary,
Thanks, are there any other active plugins, other than Cloudinary? And what theme is active?

The stack trace here unfortunately doesn't point to where the WP_Error could be coming from.

@const-cloudinary
Copy link
Contributor

@kienstra, I would start with invalid CLOUDINARY_URL, when "usage" api returns 40x/50x response or something like that.

@const-cloudinary
Copy link
Contributor

@kienstra I printed the error. it says:
disabled account in /home/consta01/public_html/wp-content/plugins/cloudinary_wordpress_v2 5/php/sync/class-push-sync.php...

@kienstra
Copy link
Contributor Author

kienstra commented Feb 3, 2020

Hi @const-cloudinary,
Thanks for your help.

@kienstra I printed the error. it says:
disabled account in /home/consta01/public_html/wp-content/plugins/cloudinary_wordpress_v2 5/php/sync/class-push-sync.php...

Would you be able to paste the rest of the error, especially the line number?

@const-cloudinary
Copy link
Contributor

const-cloudinary commented Feb 4, 2020

@kienstra It's the same line of the "Cannot use object of type WP_Error as array" . WP_Error contains this message.

You can reproduce it by deleting your Cloudinary account, clicking "Cancel my account" on this page:
https://cloudinary.com/console/settings/account

@kienstra
Copy link
Contributor Author

kienstra commented Feb 6, 2020

Hi @const-cloudinary,
Thanks for helping with the step to reproduce this.

There didn't seem to be a PHP error after canceling my Cloudinary account:

activating-cloud

I also tried wp transient delete _cloudinary_usage, and then activating the plugin.

@const-cloudinary
Copy link
Contributor

@kienstra Can you please provide me some code that I can run on my environment (add some logging entries/write notice message on the screen, etc), so I can understand what is exactly happening in my environment?

@kienstra
Copy link
Contributor Author

kienstra commented Feb 6, 2020

Hi @const-cloudinary,
Thanks, do you have xdebug enabled? That's probably going to be easier than var_dump() or print() statements.

Also, this debugging tool has helped me a lot: https://github.com/nette/tracy

@const-cloudinary
Copy link
Contributor

@kienstra This bug is reproducible on a shared hosting website I own, it will be problematic to install xdebug there.

@kienstra
Copy link
Contributor Author

kienstra commented Feb 9, 2020

Hi @const-cloudinary,
OK, thanks.

Is that a production site? If not, would it be possible to deploy this PR to it, to see if it fixes it?

If it's a production site, would it be possible to create a staging 'clone' of it?

Thanks!

@pereirinha pereirinha deleted the update/address-fatal-error-activation branch July 22, 2020 11:10
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.

3 participants