File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace Phug ;
44
5+ use Phug \Util \Partial \PathTrait ;
56use Phug \Util \SourceLocation ;
67
78/**
89 * A string reading utility that searches strings byte by byte.
910 */
1011class Reader
1112{
13+ use PathTrait;
14+
1215 /**
1316 * An array of PREG errors with a good error message.
1417 *
@@ -910,12 +913,14 @@ protected function getPregErrorText($code = null)
910913 */
911914 protected function throwException ($ message )
912915 {
916+ $ path = $ this ->getPath ();
913917 $ exception = new ReaderException (
914918 new SourceLocation (null , $ this ->line , $ this ->offset ),
915919 sprintf (
916- "Failed to read: %s \nNear: %s \nLine: %s \nOffset: %s \nPosition: %s " ,
920+ "Failed to read: %s \nNear: %s%s \nLine: %s \nOffset: %s \nPosition: %s " ,
917921 $ message ,
918922 $ this ->peek (20 ),
923+ $ path ? "\nFile: $ path " : '' ,
919924 $ this ->line ,
920925 $ this ->offset ,
921926 $ this ->position
Original file line number Diff line number Diff line change @@ -243,6 +243,19 @@ public function testMatchFailsOnPregError()
243243 (new Reader ('foobar foobar foobar ' ))->match ('(?:\D+|<\d+>)*[!?] ' );
244244 }
245245
246+ /**
247+ * @covers ::throwException
248+ * @covers \Phug\ReaderException
249+ * @expectedException \Phug\ReaderException
250+ * @expectedExceptionMessage File: path.pug
251+ */
252+ public function testPathInErrors ()
253+ {
254+ $ reader = new Reader ('foobar foobar foobar ' );
255+ $ reader ->setPath ('path.pug ' );
256+ $ reader ->match ('(?:\D+|<\d+>)*[!?] ' );
257+ }
258+
246259 /**
247260 * @covers ::match
248261 * @covers ::getMatch
You can’t perform that action at this time.
0 commit comments