{"record":{"id":"ffe83eec3b112060","repo":"composer/composer","slug":"failed-to-execute-command-erroroutput-ffe83e","errorCode":null,"errorMessage":"Failed to execute {command}\n\n{errorOutput}","messagePattern":"Failed to execute (.+?)\n\n(.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/Composer/Downloader/HgDownloader.php","lineNumber":51,"sourceCode":"        return \\React\\Promise\\resolve(null);\n    }\n\n    /**\n     * @inheritDoc\n     */\n    protected function doInstall(PackageInterface $package, string $path, string $url): PromiseInterface\n    {\n        $hgUtils = new HgUtils($this->io, $this->config, $this->process);\n\n        $cloneCommand = static function (string $url) use ($path): array {\n            return ['hg', 'clone', '--', $url, $path];\n        };\n\n        $hgUtils->runCommand($cloneCommand, $url, $path);\n\n        $command = ['hg', 'up', '--', (string) $package->getSourceReference()];\n        if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) {\n            throw new \\RuntimeException('Failed to execute ' . implode(' ', $command) . \"\\n\\n\" . $this->process->getErrorOutput());\n        }\n\n        return \\React\\Promise\\resolve(null);\n    }\n\n    /**\n     * @inheritDoc\n     */\n    protected function doUpdate(PackageInterface $initial, PackageInterface $target, string $path, string $url): PromiseInterface\n    {\n        $hgUtils = new HgUtils($this->io, $this->config, $this->process);\n\n        $ref = $target->getSourceReference();\n        $this->io->writeError(\" Updating to \".$target->getSourceReference());\n\n        if (!$this->hasMetadataRepository($path)) {\n            throw new \\RuntimeException('The .hg directory is missing from '.$path.', see https://getcomposer.org/commit-deps for more information');\n        }","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/composer/composer/blob/6ffc1177404d0c50119c22dde6564a380f4a82c9/src/Composer/Downloader/HgDownloader.php#L33-L69","documentation":"Thrown by HgDownloader::doInstall() after a successful `hg clone` when `hg up -- <sourceReference>` exits non-zero. The clone worked but the checkout of the specific revision failed, typically because the reference does not exist in the cloned repository.","triggerScenarios":"Installing an hg-sourced package with --prefer-source; the clone succeeds but the source reference in composer.lock is not present (history rewritten, revision stripped, or wrong ref).","commonSituations":"An upstream hg repo that had revisions stripped or a branch closed; composer.lock points to a revision that no longer exists; a mismatched source URL.","solutions":["Run `composer update <pkg>` to resolve a fresh, valid source reference.","Manually clone the repo and run `hg up -- <ref>` to confirm the reference is missing, then report to the maintainer.","Clear the cache and re-install to rule out a stale clone.","Switch to --prefer-dist if the provider publishes archives."],"exampleFix":"# before: locked hg revision no longer exists\ncomposer install --prefer-source\n\n# after\ncomposer update pkg-name\n# verify manually:\nhg clone <url> /tmp/pkg && hg -R /tmp/pkg up -- <ref>","handlingStrategy":"try-catch","validationCode":"// Verify the hg revision exists in the repo before checkout\nexec(sprintf('hg identify -r %s %s 2>&1', escapeshellarg($ref), escapeshellarg($url)), $out, $code);\nif ($code !== 0) {\n    // ref invalid — update package lock before attempting install\n    throw new \\RuntimeException(\"hg ref $ref not found at $url\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    $downloader->install($package, $path, $url);\n} catch (\\RuntimeException $e) {\n    if (str_contains($e->getMessage(), 'Failed to execute hg up')) {\n        // refresh lock to a valid revision and retry\n        // composer update <pkg> then re-install\n    }\n    throw $e;\n}","preventionTips":["Pin hg-sourced packages to stable tags rather than volatile dev revisions.","Run `composer update <pkg>` when an upstream hg repo strips revisions.","Verify hg refs with `hg identify` before locking them."],"tags":["mercurial","hg","checkout","source-reference","lock-file"],"analyzedSha":"6ffc1177404d0c50119c22dde6564a380f4a82c9","analyzedAt":"2026-08-07T00:01:08.491Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}