Skip to content

Commit

Permalink
Remove the throw InvalidArgumentException for the add and add_data me…
Browse files Browse the repository at this point in the history
…thods.
  • Loading branch information
nefeline committed Apr 8, 2024
1 parent 9fd2532 commit 627b911
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions plugins/woocommerce/src/Blocks/Assets/AssetDataRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ public function exists( $key ) {
* callback is invoked right before output to the screen.
* @param boolean $check_key_exists Deprecated. If set to true, duplicate data will be ignored if the key exists.
* If false, duplicate data will cause an exception.
*
* @throws InvalidArgumentException Only throws when site is in debug mode. Always logs the error.
*/
public function add( $key, $data, $check_key_exists = false ) {
if ( $check_key_exists ) {
Expand All @@ -310,15 +308,8 @@ public function add( $key, $data, $check_key_exists = false ) {
if ( $this->exists( $key ) ) {
return;
}
try {
$this->add_data( $key, $data );
} catch ( Exception $e ) {
if ( $this->debug() ) {
// bubble up.
throw $e;
}
wc_caught_exception( $e, __METHOD__, [ $key, $data ] );
}

$this->add_data( $key, $data );
}

/**
Expand Down Expand Up @@ -418,14 +409,12 @@ public function enqueue_asset_data() {
*
* @param string $key Key for the data.
* @param mixed $data Value for the data.
*
* @throws InvalidArgumentException If key is not a string or already
* exists in internal data cache.
*/
protected function add_data( $key, $data ) {
if ( ! is_string( $key ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
trigger_error( esc_html__( 'Key for the data being registered must be a string', 'woocommerce' ), E_USER_WARNING );
return;
}
if ( isset( $this->data[ $key ] ) ) {
// phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_trigger_error
Expand Down

0 comments on commit 627b911

Please sign in to comment.