Skip to content

Commit

Permalink
[TASK] Improve Warnings
Browse files Browse the repository at this point in the history
Extended warning information from the context was missing in some warnings. This makes debugging harder.

(cherry picked from commit 1a1b074)
  • Loading branch information
linawolf committed Mar 2, 2024
1 parent cb1befb commit 9437ff8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use function assert;
use function get_debug_type;
use function sprintf;

final class ConfigurationBlockDirective extends SubDirective
{
Expand Down Expand Up @@ -59,7 +60,10 @@ protected function processSub(
$tabs = [];
foreach ($collectionNode->getValue() as $child) {
if (!$child instanceof CodeNode) {
$this->logger->warning('The ".. configuration-block::" directive only supports code blocks, "' . get_debug_type($child) . '" given.');
$this->logger->warning(
sprintf('The ".. configuration-block::" directive only supports code blocks, "%s" given.', get_debug_type($child)),
$blockContext->getLoggerInformation(),
);

continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

use function array_filter;
use function array_map;
use function array_merge;
use function assert;
use function count;
use function explode;
Expand Down Expand Up @@ -69,7 +70,10 @@ public function processNode(
->readStream((string) $directive->getOption('file')->getValue());

if ($csvStream === false) {
$this->logger->error('Unable to read CSV file {file}', ['file' => $directive->getOption('file')->getValue()]);
$this->logger->error(
'Unable to read CSV file {file}',
array_merge(['file' => $directive->getOption('file')->getValue()], $blockContext->getLoggerInformation()),
);

return new GenericNode('csv-table');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ protected function processSub(
Directive $directive,
): Node|null {
if (count($collectionNode->getChildren()) !== 1) {
$this->logger->warning(sprintf('The table directive may contain exactly one table. %s children found', count($collectionNode->getChildren())));
$this->logger->warning(
sprintf('The table directive may contain exactly one table. %s children found', count($collectionNode->getChildren())),
$blockContext->getLoggerInformation(),
);

return $collectionNode;
}

$tableNode = $collectionNode->getChildren()[0];
if (!$tableNode instanceof TableNode) {
$this->logger->warning(sprintf('The table directive may contain exactly one table. A node of type %s was found. ', $tableNode::class));
$this->logger->warning(
sprintf('The table directive may contain exactly one table. A node of type %s was found. ', $tableNode::class),
$blockContext->getLoggerInformation(),
);

return $collectionNode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function render(Node $node, RenderContext $renderContext): string
'No template found for rendering directive "%s". Expected template "%s"',
$node->getName(),
$template,
));
), $renderContext->getLoggerInformation());
$template = 'body/directive/not-found.html.twig';

return $this->renderer->renderTemplate($renderContext, $template, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function render(Node $node, RenderContext $renderContext): string
'No template found for rendering directive "%s". Expected template "%s"',
$node->getName(),
$template,
));
), $renderContext->getLoggerInformation());
$template = 'body/directive/not-found.html.twig';

return $this->renderer->renderTemplate($renderContext, $template, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ protected function processSub(

$tabs[] = $child;
} else {
$this->logger->warning('The "tabs" directive may only contain children of type "tab". The following node was found: ' . $child::class);
$this->logger->warning(
'The "tabs" directive may only contain children of type "tab". The following node was found: ' . $child::class,
$blockContext->getLoggerInformation(),
);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
app.WARNING: No template found for rendering directive "some-unknown-directive". Expected template "body/directive/some-unknown-directive.html.twig" [] []
app.WARNING: No template found for rendering directive "some-unknown-directive". Expected template "body/directive/some-unknown-directive.html.twig" {"rst-file":"index"} []

0 comments on commit 9437ff8

Please sign in to comment.