Skip to content

Commit

Permalink
Also handle error when Examples table throws NodeException
Browse files Browse the repository at this point in the history
  • Loading branch information
ciaranmcnulty committed Feb 10, 2021
1 parent 363dd69 commit a79bb0a
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions src/Behat/Gherkin/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,15 @@ protected function parseStep()
*/
protected function parseExamples()
{
$token = $this->expectTokenType('Examples');

$keyword = $token['keyword'];

$keyword = ($this->expectTokenType('Examples'))['keyword'];
$tags = empty($this->tags) ? array() : $this->popTags();
$table = $this->parseTableRows();

return new ExampleTableNode($this->parseTableRows(), $keyword, $tags);
try {
return new ExampleTableNode($table, $keyword, $tags);
} catch(NodeException $e) {
$this->rethrowNodeException($e);
}
}

/**
Expand All @@ -571,11 +573,7 @@ protected function parseTable()
try {
return new TableNode($table);
} catch(NodeException $e) {
throw new ParserException(
$e->getMessage() . ($this->file ? ' in file '.$this->file : ''),
0,
$e
);
$this->rethrowNodeException($e);
}
}

Expand Down Expand Up @@ -744,4 +742,13 @@ private function normalizeStepNodeKeywordType(StepNode $node, array $steps = arr
}
return $node;
}

private function rethrowNodeException(NodeException $e): void
{
throw new ParserException(
$e->getMessage() . ($this->file ? ' in file ' . $this->file : ''),
0,
$e
);
}
}

0 comments on commit a79bb0a

Please sign in to comment.