shaper icon indicating copy to clipboard operation
shaper copied to clipboard

Validation errors are lost when exception is thrown

Open mxr576 opened this issue 2 years ago • 0 comments

justinrainbow/json-schema's Validator object is stateless, so even is $this->doUndoTransform($data, $context) performs a validation and concludes that the output failed on the schema validation in the parent scope, the $validator = $this->getOutputValidator(); $validator->getErrors(); call is going to return an empty array because validation errors are only available on the object after $validator->isValid() is called.

https://github.com/e0ipso/shaper/blob/master/src/DataAdaptor/DataAdaptorTransformerTrait.php#L57-L66

I have spotted this when I analyzed Drupal log and I saw this

TypeError: Adaptor Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase returned invalid output data: [] in Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase->undoTransform() (line 66 of /mnt/files/local_mount/build/vendor/e0ipso/shaper/src/DataAdaptor/DataAdaptorTransformerTrait.php)

instead of this

TypeError: Adaptor Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase returned invalid output data: [{"property":"format","pointer":"/format","message":"NULL value found, but a string is required","constraint":"type","context":1}] in Drupal\jsonapi_extras\Plugin\ResourceFieldEnhancerBase->undoTransform() (line 66 of /mnt/files/local_mount/build/vendor/e0ipso/shaper/src/DataAdaptor/DataAdaptorTransformerTrait.php)

mxr576 avatar Feb 23 '23 12:02 mxr576