Obviously I'm doing something wrong while testing data types with wsclient, but Rules should not end up in a fatal error. Code fragment in rules.core.inc:

  public function applyDataSelector($selector) {
    $parts = explode(':', str_replace('-', '_', $selector), 2);
    if (($vars = $this->availableVariables()) && isset($vars[$parts[0]]['type'])) {
      $data = NULL;
      $wrapper = rules_wrap_data($data, $vars[$parts[0]], TRUE);
      if (count($parts) > 1 && $wrapper instanceof EntityMetadataWrapper) {
        try {
          foreach (explode(':', $parts[1]) as $name) {
            $wrapper = $wrapper->get($name);
          }
        }
        // In case of an exception or we were unable to get a wrapper, return FALSE.
        catch (EntityMetadataWrapperException $e) {
          return FALSE;
        }
      }
    }
    return isset($wrapper) ? $wrapper : FALSE;
  }

EntityMetadataWrapper does not implement a get() method, so the instanceof check is wrong here. Only EntityStructureWrapper and EntityListWrapper implement a get() method, so should we check for that instead?

CommentFileSizeAuthor
#3 1028900-rules-dx.patch1.47 KBklausi

Comments

klausi’s picture

Component: Rules Core » Rules Engine

Same error in rules.states.inc when executing the rule from code:
Fatal error: Call to undefined method EntityValueWrapper::get() in rules/includes/rules.state.inc on line 277

fago’s picture

Title: Fatal error: Call to undefined method EntityValueWrapper::get() in rules/includes/rules.core.inc on line 686 » Improve DX when working with wrong property info
Category: bug » task

If the problem stems from your code providing wrong info, there is no bug but a feature-request to improve DX when wrong property info is specified/used.
We could wrap the get() call into a suiting check and bail out nicely if necessary.

klausi’s picture

Status: Active » Needs review
StatusFileSize
new1.47 KB

In my case i had a struct data type without property information. entity_metadata_wrapper() returns an EntityValueWrapper for that , which seems to be wrong and should be fixed, too. However, Rules should also check for the correct classes, patch attached.

fago’s picture

Status: Needs review » Fixed

looks good, thanks committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.