You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the implementation for most Keyring services (maybe all?) a request that results in an error returns an instance of Keyring_Error.
This is all good until you see that Keyring_Error is a subclass of WP_Error with no specific implementation, and as such, you would expect that it'd be compatible with how WP_Error is used in WP. For example, the following standard error-checking pattern from the WP world can result in a PHP notice/warning/error if $result is of type Keyring_Error:
if ( is_wp_error( $result ) ) {
echo$result->get_error_message();
}
In particular, because there are a bunch of places in the codebase where Keyring_Error is instantiated passing an error code as first argument and the HTTP response object as second argument, the "error message" stored in the object is frequently not a string. This can happen, for example, if the server returns something other than a 2xx code.
For comparison, this is WP_Error's constructor signature:
The second argument should be a string, which would also enable Keyring_Error::get_error_message() to return something that can be printed on screen or logged to a log file.
Most likely, the response was meant to go into the 3rd parameter ($data), which can in fact be of any type.
The text was updated successfully, but these errors were encountered:
jorgeatorres
changed the title
Keyring_Error is sometimes instantiated in a way that is incompatible with the definition of WP_ErrorKeyring_Error is sometimes instantiated in a way that is incompatible with usage of WP_ErrorMar 2, 2022
In the implementation for most Keyring services (maybe all?) a request that results in an error returns an instance of
Keyring_Error
.This is all good until you see that
Keyring_Error
is a subclass ofWP_Error
with no specific implementation, and as such, you would expect that it'd be compatible with howWP_Error
is used in WP. For example, the following standard error-checking pattern from the WP world can result in a PHP notice/warning/error if$result
is of typeKeyring_Error
:In particular, because there are a bunch of places in the codebase where
Keyring_Error
is instantiated passing an error code as first argument and the HTTP response object as second argument, the "error message" stored in the object is frequently not a string. This can happen, for example, if the server returns something other than a 2xx code.For comparison, this is
WP_Error
's constructor signature:The second argument should be a string, which would also enable
Keyring_Error::get_error_message()
to return something that can be printed on screen or logged to a log file.Most likely, the response was meant to go into the 3rd parameter (
$data
), which can in fact be of any type.Full example:
The text was updated successfully, but these errors were encountered: