MVC / Core - when throwing Validation\Exception, make sure to add the current field contents when we can find it. This improves model migration log output and helps debugging issues. related to https://github.com/opnsense/core/issues/5693

This commit is contained in:
Ad Schellevis 2022-04-10 14:59:26 +02:00
parent 714eca2b18
commit 626c3dbf55

View File

@ -568,6 +568,10 @@ abstract class BaseModel
foreach ($messages as $msg) {
$exception_msg_part = "[" . get_class($this) . ":" . $msg->getField() . "] ";
$exception_msg_part .= $msg->getMessage();
$field_value = $this->getNodeByReference($msg->getField());
if (!empty($field_value)) {
$exception_msg_part .= sprintf("{%s}", $field_value);
}
$exception_msg .= "$exception_msg_part\n";
// always log validation errors
$logger->error($exception_msg_part);