Skip to content

Conversation

@reithor
Copy link
Contributor

@reithor reithor commented Oct 28, 2025

PR adds enhanced exception handling to contentCreate
(ContentFieldValidationException::createNewWithMultiline($errors) was introduced in ezsystems/ezplatform-kernel#329)

Without PR, thrown errors will show up as :

Content fields did not validate

With PR, details regarding affected fields will be shown:

  Content fields did not validate:
  - Value for required field definition 'short_name' with language 'eng-GB' is empty
  - ...

@sonarqubecloud
Copy link

Comment on lines -62 to +65
$exception->setMessageTemplate('Content "%contentName%" fields did not validate: %errors%');
$exception->setMessageTemplate('Content%contentName%fields did not validate: %errors%');
$exception->setParameters([
'%errors%' => $exception->generateValidationErrorsMessages(),
'%contentName%' => $exception->contentName !== null ? $exception->contentName : '',
'%contentName%' => $exception->contentName !== null ? ' "' . $exception->contentName . '" ' : ' ',
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this change needed? I think we cannot have empty contentName or do we?

Copy link
Contributor Author

@reithor reithor Oct 28, 2025

Choose a reason for hiding this comment

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

In function createContent when throwing the error we do not yet have a Content Object - just $contentCreateStruct and no contentName.
Even in updateContent we might have errors in fields that make contentName empty.

But you are right, the above looks 'unmotivated'.
Main reason for the change was the existing test https://github.com/ibexa/core/blob/main/tests/lib/Repository/Service/Mock/ContentTest.php#L2498 that checks the error message.
More specific:
Without the above change, the new error message for createContent will be:

Content "" fields did not validate:
  - ..
  - ...

This lets the test fail, as it expects Content fields did not validate .
Probably better to change the test ...

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.

5 participants