Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cast table node exceptions into ParserExceptions when throwing #216

Merged
merged 4 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Behat/Gherkin/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace Behat\Gherkin;

use Behat\Gherkin\Exception\LexerException;
use Behat\Gherkin\Exception\NodeException;
use Behat\Gherkin\Exception\ParserException;
use Behat\Gherkin\Node\BackgroundNode;
use Behat\Gherkin\Node\ExampleTableNode;
Expand Down Expand Up @@ -565,7 +566,16 @@ protected function parseExamples()
*/
protected function parseTable()
{
return new TableNode($this->parseTableRows());
try {
return new TableNode($this->parseTableRows());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would probably keep the parseTableRows outside the try/catch so that we catch only the exceptions from TableNode.

}
catch(NodeException $e) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be on the previous line to follow PSR-2/PSR-12

throw new ParserException(
$e->getMessage() . $this->file ? ' in file '.$this->file : '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are missing braces around the ternary. The current code is executed as ($e->getMessage() . $this->file) ? ' in file '.$this->file : '' which is not what you want.

0,
$e
);
}
}

/**
Expand Down
1 change: 0 additions & 1 deletion tests/Behat/Gherkin/Cucumber/CompatibilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class CompatibilityTest extends TestCase
];

private $parsedButShouldNotBe = [
'inconsistent_cell_count.feature' => 'Inconsistent cells count throws low level exception not ParserException',
'invalid_language.feature' => 'Invalid language is silently ignored',
'whitespace_in_tags.feature' => 'Whitespace in tags is tolerated',
];
Expand Down