Browse Source

Output a hint that maybe you are not in the right directory, fixes #8404

Jordi Boggiano 5 years ago
parent
commit
af86ca1fb3
1 changed files with 9 additions and 1 deletions
  1. 9 1
      src/Composer/Command/RequireCommand.php

+ 9 - 1
src/Composer/Command/RequireCommand.php

@@ -139,7 +139,15 @@ EOT
         }
 
         $phpVersion = $this->repos->findPackage('php', '*')->getPrettyVersion();
-        $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'), $phpVersion, $preferredStability, !$input->getOption('no-update'));
+        try {
+            $requirements = $this->determineRequirements($input, $output, $input->getArgument('packages'), $phpVersion, $preferredStability, !$input->getOption('no-update'));
+        } catch (\Exception $e) {
+            if ($this->newlyCreated) {
+                throw new \RuntimeException('No composer.json present in the current directory, this may be the cause of the following exception.', 0, $e);
+            }
+
+            throw $e;
+        }
 
         $requireKey = $input->getOption('dev') ? 'require-dev' : 'require';
         $removeKey = $input->getOption('dev') ? 'require' : 'require-dev';