File tree 2 files changed +10
-25
lines changed
2 files changed +10
-25
lines changed Original file line number Diff line number Diff line change @@ -106,41 +106,26 @@ public function appendMessage($rawMessage): void
106
106
107
107
private function updateRepr (): void
108
108
{
109
- $ this ->message = $ this ->rawMessage ;
110
-
111
- if ($ this ->source && $ this ->source ->getPath () && $ this ->lineno > 0 ) {
112
- $ this ->file = $ this ->source ->getPath ();
109
+ if ($ this ->lineno > 0 ) {
113
110
$ this ->line = $ this ->lineno ;
114
-
115
- return ;
116
111
}
117
-
118
- $ dot = false ;
119
- if (str_ends_with ($ this ->message , '. ' )) {
120
- $ this ->message = substr ($ this ->message , 0 , -1 );
121
- $ dot = true ;
112
+ if ($ this ->source && $ this ->source ->getPath ()) {
113
+ $ this ->file = $ this ->source ->getPath ();
122
114
}
123
115
124
- $ questionMark = false ;
125
- if (str_ends_with ($ this ->message , '? ' )) {
116
+ $ this ->message = $ this ->rawMessage ;
117
+ $ last = substr ($ this ->message , -1 );
118
+ if ($ punctuation = '. ' === $ last || '? ' === $ last ? $ last : '' ) {
126
119
$ this ->message = substr ($ this ->message , 0 , -1 );
127
- $ questionMark = true ;
128
120
}
129
-
130
121
if ($ this ->source && $ this ->source ->getName ()) {
131
122
$ this ->message .= \sprintf (' in "%s" ' , $ this ->source ->getName ());
132
123
}
133
-
134
124
if ($ this ->lineno > 0 ) {
135
125
$ this ->message .= \sprintf (' at line %d ' , $ this ->lineno );
136
126
}
137
-
138
- if ($ dot ) {
139
- $ this ->message .= '. ' ;
140
- }
141
-
142
- if ($ questionMark ) {
143
- $ this ->message .= '? ' ;
127
+ if ($ punctuation ) {
128
+ $ this ->message .= $ punctuation ;
144
129
}
145
130
}
146
131
Original file line number Diff line number Diff line change @@ -98,7 +98,7 @@ public function testTwigExceptionGuessWithMissingVarAndFilesystemLoader()
98
98
99
99
$ this ->fail ();
100
100
} catch (RuntimeError $ e ) {
101
- $ this ->assertEquals ('Variable "foo" does not exist. ' , $ e ->getMessage ());
101
+ $ this ->assertEquals ('Variable "foo" does not exist in "index.html" at line 3 . ' , $ e ->getMessage ());
102
102
$ this ->assertEquals (3 , $ e ->getTemplateLine ());
103
103
$ this ->assertEquals ('index.html ' , $ e ->getSourceContext ()->getName ());
104
104
$ this ->assertEquals (3 , $ e ->getLine ());
@@ -117,7 +117,7 @@ public function testTwigExceptionGuessWithExceptionAndFilesystemLoader()
117
117
118
118
$ this ->fail ();
119
119
} catch (RuntimeError $ e ) {
120
- $ this ->assertEquals ('An exception has been thrown during the rendering of a template ("Runtime error..."). ' , $ e ->getMessage ());
120
+ $ this ->assertEquals ('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3 . ' , $ e ->getMessage ());
121
121
$ this ->assertEquals (3 , $ e ->getTemplateLine ());
122
122
$ this ->assertEquals ('index.html ' , $ e ->getSourceContext ()->getName ());
123
123
$ this ->assertEquals (3 , $ e ->getLine ());
You can’t perform that action at this time.
0 commit comments