Skip to content

Commit

Permalink
Better error message for invalid autoload paths in composer.json (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Apr 8, 2024
1 parent ccb1e5c commit 6ca96e6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Analyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ private function listPhpFilesIn(string $path): Generator
try {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
} catch (UnexpectedValueException $e) {
throw new InvalidPathException("Unable to list files in $path", 0, $e);
throw new InvalidPathException("Unable to list files in $path", $e);
}

foreach ($iterator as $entry) {
Expand Down
4 changes: 2 additions & 2 deletions src/ComposerJson.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,13 @@ private function extractAutoloadPaths(string $basePath, array $autoload, bool $i
}

foreach ($globPaths as $globPath) {
$result[Path::realpath($globPath)] = $isDev;
$result[Path::normalize($globPath)] = $isDev;
}

continue;
}

$result[Path::realpath($absolutePath)] = $isDev;
$result[Path::normalize($absolutePath)] = $isDev;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@
namespace ShipMonk\ComposerDependencyAnalyser\Exception;

use RuntimeException as NativeRuntimeException;
use Throwable;

class RuntimeException extends NativeRuntimeException
{

public function __construct(string $message, ?Throwable $previous = null)
{
parent::__construct($message, 0, $previous);
}

}
11 changes: 7 additions & 4 deletions src/Initializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function __construct(

/**
* @throws InvalidConfigException
* @throws InvalidPathException
*/
public function initConfiguration(
CliOptions $options,
Expand All @@ -93,7 +92,7 @@ public function initConfiguration(
return require $configPath;
})();
} catch (Throwable $e) {
throw new InvalidConfigException(get_class($e) . " in {$e->getFile()}:{$e->getLine()}\n > " . $e->getMessage(), 0, $e);
throw new InvalidConfigException("Error while loading configuration from '$configPath':\n\n" . get_class($e) . " in {$e->getFile()}:{$e->getLine()}\n > " . $e->getMessage(), $e);
}

if (!$config instanceof Configuration) {
Expand Down Expand Up @@ -135,8 +134,12 @@ public function initConfiguration(
}

if ($config->shouldScanComposerAutoloadPaths()) {
foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) {
$config->addPathToScan($absolutePath, $isDevPath);
try {
foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) {
$config->addPathToScan($absolutePath, $isDevPath);
}
} catch (InvalidPathException $e) {
throw new InvalidConfigException('Error while processing composer.json autoload path: ' . $e->getMessage(), $e);
}

if ($config->getPathsToScan() === []) {
Expand Down

0 comments on commit 6ca96e6

Please sign in to comment.