Skip to content

Commit 6ca96e6

Browse files
authored
Better error message for invalid autoload paths in composer.json (#117)
1 parent ccb1e5c commit 6ca96e6

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

src/Analyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ private function listPhpFilesIn(string $path): Generator
345345
try {
346346
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
347347
} catch (UnexpectedValueException $e) {
348-
throw new InvalidPathException("Unable to list files in $path", 0, $e);
348+
throw new InvalidPathException("Unable to list files in $path", $e);
349349
}
350350

351351
foreach ($iterator as $entry) {

src/ComposerJson.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ private function extractAutoloadPaths(string $basePath, array $autoload, bool $i
112112
}
113113

114114
foreach ($globPaths as $globPath) {
115-
$result[Path::realpath($globPath)] = $isDev;
115+
$result[Path::normalize($globPath)] = $isDev;
116116
}
117117

118118
continue;
119119
}
120120

121-
$result[Path::realpath($absolutePath)] = $isDev;
121+
$result[Path::normalize($absolutePath)] = $isDev;
122122
}
123123
}
124124

src/Exception/RuntimeException.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
namespace ShipMonk\ComposerDependencyAnalyser\Exception;
44

55
use RuntimeException as NativeRuntimeException;
6+
use Throwable;
67

78
class RuntimeException extends NativeRuntimeException
89
{
910

11+
public function __construct(string $message, ?Throwable $previous = null)
12+
{
13+
parent::__construct($message, 0, $previous);
14+
}
15+
1016
}

src/Initializer.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function __construct(
6868

6969
/**
7070
* @throws InvalidConfigException
71-
* @throws InvalidPathException
7271
*/
7372
public function initConfiguration(
7473
CliOptions $options,
@@ -93,7 +92,7 @@ public function initConfiguration(
9392
return require $configPath;
9493
})();
9594
} catch (Throwable $e) {
96-
throw new InvalidConfigException(get_class($e) . " in {$e->getFile()}:{$e->getLine()}\n > " . $e->getMessage(), 0, $e);
95+
throw new InvalidConfigException("Error while loading configuration from '$configPath':\n\n" . get_class($e) . " in {$e->getFile()}:{$e->getLine()}\n > " . $e->getMessage(), $e);
9796
}
9897

9998
if (!$config instanceof Configuration) {
@@ -135,8 +134,12 @@ public function initConfiguration(
135134
}
136135

137136
if ($config->shouldScanComposerAutoloadPaths()) {
138-
foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) {
139-
$config->addPathToScan($absolutePath, $isDevPath);
137+
try {
138+
foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) {
139+
$config->addPathToScan($absolutePath, $isDevPath);
140+
}
141+
} catch (InvalidPathException $e) {
142+
throw new InvalidConfigException('Error while processing composer.json autoload path: ' . $e->getMessage(), $e);
140143
}
141144

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

0 commit comments

Comments
 (0)