Skip to content

Commit 25ce403

Browse files
CopilotArnaudLigny
andauthored
Improve DI container fallback: specific exception handling and logging (#2289)
* Improve DI fallback: catch specific exception and add logging * Fix Parsedown DI config to explicitly inject Builder * Address code review feedback: improve comments and remove unnecessary namespace prefix Co-authored-by: ArnaudLigny <80580+ArnaudLigny@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ArnaudLigny <80580+ArnaudLigny@users.noreply.github.com>
1 parent 64b8cb4 commit 25ce403

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/Builder.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Cecil\Generator\GeneratorManager;
2020
use Cecil\Logger\PrintLogger;
2121
use DI\Container;
22+
use DI\NotFoundException;
2223
use Psr\Log\LoggerAwareInterface;
2324
use Psr\Log\LoggerInterface;
2425
use Symfony\Component\Finder\Finder;
@@ -280,11 +281,18 @@ public function build(array $options): self
280281
$steps = [];
281282
// init...
282283
foreach (self::STEPS as $step) {
283-
// Use DI container to create steps
284+
// Use DI container to create steps with dependency injection.
285+
// All steps defined in the DI container configuration should be resolved from the container.
286+
// Falls back to direct instantiation only if a step is not registered in the container.
284287
try {
285288
$stepObject = $this->container->get($step);
286-
} catch (\Exception $e) {
289+
} catch (NotFoundException $e) {
287290
// Fallback for steps not declared in the container
291+
// This should rarely happen as all steps in STEPS constant are defined in the DI container configuration
292+
$this->getLogger()->warning(sprintf(
293+
'Step %s not found in DI container, using direct instantiation as fallback',
294+
$step
295+
));
288296
$stepObject = new $step($this);
289297
}
290298
$stepObject->init($this->options);

0 commit comments

Comments
 (0)