-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2.2] add support for optional custom error message for Configura... #5094
Conversation
@stof any updates on this one? or is left to starve to death? |
@cordoval I don't think adding yet another method is a good idea. A better solution would be to use the info attached to the node to enhance the error message |
+1 for @stof idea. |
@cordoval Can you work on an evolution of this PR based on the feedback? |
@cordoval Thanks a lot. |
I have thought in two ways to refactor: $message = sprintf(
'Invalid configuration for path "%s": %s',
$this->getPath(),
$invalid->getMessage()
);
if ($this->getInfo() != null) {
$message .= sprintf("\nError message: %s.", $this->getInfo());
}
$ex = new InvalidConfigurationException($message, $invalid->getCode(), $invalid);
$ex->setPath(...)
throw $ex; into $message = sprintf(
'Invalid configuration for path "%s": %s',
$this->getPath(),
$invalid->getMessage()
)
$ex = new InvalidConfigurationException($this->addErrorHintMessageIfPresent($message), $invalid->getCode(), $invalid);
$ex->setPath(...)
throw $ex; and have the helper method to the BaseNode class to avoid locs everywhere or even implementing this into the exception base class or some other but then do: $ex->setPath(...);
$ex->setInfo($this->getInfo()); |
I will also work on changes to the documentation after this is re-factored and put into shape for merge. |
I don't think this works that well. With such an implementation, all you could add is a description of the node in question. The reason why error message does not work is simply that there might be many reasons for why something is going wrong. So, for each of these reasons, you would need to add a different message. If you really would like to do that, this could work by adding first an id for each message that could occur (or generate one), and then having a map on the node which replaces the generic message with the custom one. This would be a bit of work though. If you instead only would like to add a description of the node, I'm not really convinced this is useful either as the error message still is the generic one, and not a custom error message. |
@schmittjoh the idea for the info in this case is to provide a sample peek of what the configuration looks like or a hint why usually things went wrong in terms of how the configuration is used. We are not trying to map a message to every problem as in the case where we have constraints and we want to specify things. I think for that we have the custom nodes that can be extended for a given specific data constraint/requirements, like the NumericNode or IntegerNode which were PRed. This is a small tiny helper hint to have. But yeah i agree with you that it is no more than that. Maybe @lsmith77 wanted to have just that or maybe more? I think this is like the run-time version of config:dump-reference command. |
@schmittjoh if there are multiple causes you can list them all. i expect this to mostly be used to clarify things based on issue tickets. ie. users express some confusion about an error message, and then you add some clarifications. sort of an evolutionary process. |
@@ -205,6 +205,9 @@ protected function finalizeValue($value) | |||
if (!array_key_exists($name, $value)) { | |||
if ($child->isRequired()) { | |||
$msg = sprintf('The child node "%s" at path "%s" must be configured.', $name, $this->getPath()); | |||
if ($this->getInfo() != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should be null !== $this->getInfo()
@cordoval Please update all nodes according to my comments and then squash your commits. |
What is the status of this PR? |
@fabpot i will review it tonight thanks |
gah, i got swamped at my work, anyone be willing to take a look and what is left please? if not then i can say i can try looking at beginning of next week |
@fabpot ok iam working on this now, i got time, i will basically finish the tests which i think is the only thing left |
Looks good to me but we repeat the same code over and over again. Can we try to make the code more future proof. what about adding a |
…info [symfony#1666] RFC: add support for optional custom error message for Configuration validation errors [symfony#1666] remove method that was previously added on NodeDefinition since we will reuse info method [symfony#1666] remove errorMessage methods introduced in BaseNode class since we are going through info this time [symfony#1666] reuse getInfo message for error output in exception for ScalarNode class [symfony#1666] clean up of ScalarNode adding of info exception message [symfony#1666] reuse getInfo message for error output in exception for VariableNode class [symfony#1666] correct a typo explicited -> made explicit [symfony#1666] reuse getInfo message for error output in exception for NumericNode class [symfony#1666] reuse getInfo message for error output in exception for FloatNode and IntegerNode [symfony#1666] reuse getInfo message for error output in exception for EnumNode class [symfony#1666] reuse getInfo message for error output in exception for BooleanNode class [symfony#1666] reuse getInfo message for error output in exception for BaseNode class [symfony#1666] reuse getInfo message for error output in exception for ArrayNode class [symfony#1666] remove test on TreeBuilder test getInfo since it becomes redundant as info already is tested [symfony#1666] fix test to use getInfo for ScalarNodeTest address comments swtich to if (->getInfo() != null) {
@fabpot working on this right now |
@fabpot ok done, the error is because of another failing test in master, but so everything else is passing. 👍 thanks for helping me out, I think some more refactoring could be done but it could also be overkill So all good now |
@@ -204,9 +204,12 @@ protected function finalizeValue($value) | |||
foreach ($this->children as $name => $child) { | |||
if (!array_key_exists($name, $value)) { | |||
if ($child->isRequired()) { | |||
$msg = sprintf('The child node "%s" at path "%s" must be configured.', $name, $this->getPath()); | |||
$ex = new InvalidConfigurationException($msg); | |||
$ex = new InvalidConfigurationException(sprintf('The child node "%s" at path "%s" must be configured.', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you revert to everything on one line? (same below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do the same for the other exceptions? Thanks.
@cordoval Any news on my comments? |
@fabpot can this still get on 2.2 release? |
Yes, but it must be mergeable before Friday. |
@cordoval Any chance you address my latest comments? I'm about to close it as this is not something we must have. |
Closing as this code have serious drawbacks. Feel free to reopen whenever the code is ready. |
ok @fabpot i will bookmark this to work on, sorry about the delay, 👶 |
RFC: ref #1666
Basically this is the start, but i wanted to ask which one of these options is better:
this requires a modification of the throw specific expection passing Exception($this) meaning it is getting
the current node or the node from which the exception is being thrown
this would require changes in every particular class
Please vote whether 1 or 2 is more fit
Thanks to all symfony2 community :D