From af86ca1fb3bde63ec351d78f431da5502318bc3f Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 1 Nov 2019 16:32:34 +0100 Subject: [PATCH] Output a hint that maybe you are not in the right directory, fixes #8404 --- src/Composer/Command/RequireCommand.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Composer/Command/RequireCommand.php b/src/Composer/Command/RequireCommand.php index 1fa280d3f..bb99fc310 100644 --- a/src/Composer/Command/RequireCommand.php +++ b/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';