Skip to content

Commit 73a44ed

Browse files
Merge pull request #381 from markusweigelt/improve-error-handling
[IMPROVEMENT] Improve error handling of validation
2 parents 2383c23 + 9f2c361 commit 73a44ed

File tree

3 files changed

+54
-38
lines changed

3 files changed

+54
-38
lines changed

Classes/Validation/Common/NodeListValidator.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use DOMNode;
2929
use DOMNodeList;
3030
use DOMXPath;
31+
use Exception;
3132
use TYPO3\CMS\Extbase\Error\Result;
3233

3334
/**
@@ -61,7 +62,22 @@ public function __construct(DOMXPath $xpath, Result $result, string $expression,
6162
parent::__construct($severityLevel);
6263
$this->expression = $expression;
6364
$this->contextNode = $contextNode;
64-
$this->nodeList = $xpath->query($expression, $contextNode);
65+
try {
66+
$nodeList = $xpath->query($expression, $contextNode);
67+
if ($nodeList === false) {
68+
throw new Exception(
69+
'A syntax error occurred while querying'
70+
);
71+
}
72+
$this->nodeList = $nodeList;
73+
} catch (Exception $e) {
74+
$errorMessage = sprintf('%s with XPath expression "%s"', $e->getMessage(), $this->expression);
75+
if ($this->contextNode) {
76+
$errorMessage .= sprintf(' under "%s"', $this->contextNode->getNodePath());
77+
}
78+
throw new Exception($errorMessage, $e->getCode(), $e);
79+
}
80+
6581
$this->result = $result;
6682
}
6783

Resources/Private/Less/components/validationform.less

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,59 +31,59 @@
3131
margin: 1.5em 0;
3232
margin-top: 0.5em;
3333
}
34+
}
3435

35-
.callout {
36-
border-radius: .25rem;
37-
box-shadow: 0 1px 3px rgba(0 0 0 / 12%), 0 1px 2px rgba(0 0 0 / 24%);
38-
background-color: #fff;
39-
border-left: 5px solid #e9ecef;
40-
margin-bottom: 1rem;
41-
padding: 1rem;
36+
.callout {
37+
border-radius: .25rem;
38+
box-shadow: 0 1px 3px rgba(0 0 0 / 12%), 0 1px 2px rgba(0 0 0 / 24%);
39+
background-color: #fff;
40+
border-left: 5px solid #e9ecef;
41+
margin-bottom: 1rem;
42+
padding: 1rem;
4243

43-
&.callout-error {
44-
border-left-color: @error-red;
44+
&.callout-error {
45+
border-left-color: @error-red;
4546

46-
h3 {
47-
color: @error-red;
48-
}
47+
h3 {
48+
color: @error-red;
4949
}
50+
}
5051

51-
&.callout-warning {
52-
border-left-color: @warning-yellow;
52+
&.callout-warning {
53+
border-left-color: @warning-yellow;
5354

54-
h3 {
55-
color: @warning-yellow;
56-
}
55+
h3 {
56+
color: @warning-yellow;
5757
}
58+
}
5859

59-
&.callout-notice {
60-
border-left-color: @base-blue;
60+
&.callout-notice {
61+
border-left-color: @base-blue;
6162

62-
h3 {
63-
color: @base-blue;
64-
}
63+
h3 {
64+
color: @base-blue;
6565
}
66+
}
6667

67-
&.callout-success {
68-
border-left-color: @okay-green;
68+
&.callout-success {
69+
border-left-color: @okay-green;
6970

70-
h3 {
71-
color: @okay-green;
72-
}
71+
h3 {
72+
color: @okay-green;
7373
}
74+
}
7475

75-
ul li {
76-
margin: 0.5em 0;
76+
ul li {
77+
margin: 0.5em 0;
7778

78-
&::before {
79-
top: -1px;
80-
}
79+
&::before {
80+
top: -1px;
8181
}
82+
}
8283

83-
h3 {
84-
margin: 0;
85-
font-size: 18px;
86-
}
84+
h3 {
85+
margin: 0;
86+
font-size: 18px;
8787
}
8888
}
8989
}

Resources/Public/Css/webStyles.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)