While working on improving my Gitlab project_browser source, I find it throws an exception if the project type is ProjectType::Recipe:

The website encountered an unexpected error. Try again later.

OutOfBoundsException: Package "vbouchet/te_security" is not installed in Composer\InstalledVersions::getInstallPath() (line 241 of vendor/composer/InstalledVersions.php).
Drupal\project_browser\RecipeActivator->getPath(Object) (Line: 71)

here is the getPath method:

  /**
   * Returns the absolute path of an installed recipe, if known.
   *
   * @param \Drupal\project_browser\ProjectBrowser\Project $project
   *   A project object with info about the recipe.
   *
   * @return string|null
   *   The absolute local path of the recipe, or NULL if it's not installed.
   */
  private function getPath(Project $project): ?string {
    if ($project->packageName === 'drupal/core') {
      // The machine name is the directory name.
      // @see \Drupal\project_browser\Plugin\ProjectBrowserSource\Recipes::getProjects()
      return $this->appRoot . '/core/recipes/' . $project->machineName;
    }
    $path = InstalledVersions::getInstallPath($project->packageName);
    return $path ? $this->fileSystem->realpath($path) : NULL;
  }

I am wondering if it even makes sense to check for "installed recipe" given a recipe is only "applied". However, I understand we are not really trying to know if a recipe is installed but more to find its local path. Maybe we just need to adapt the wording of the method doc and catch the exception to return NULL.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

vbouchet created an issue. See original summary.

vbouchet’s picture

Status: Active » Needs review
phenaproxima’s picture

Title: Fatal error in RecipeActivator::getPath() » Fatal error in RecipeActivator::getPath() if the package is not physically installed
Status: Needs review » Needs work
Issue tags: +Needs tests

Makes sense to me, but ideally we would have unit test coverage here.

thejimbirch’s picture

Running into this also on https://www.drupal.org/project/api_browser

The patch fixes the issue.

Leaving as Needs work as tests have been requested.

kunal.sachdev made their first commit to this issue’s fork.

phenaproxima’s picture

Assigned: Unassigned » phenaproxima
Issue tags: -Needs tests

Assigning to myself to figure out why CI is failing. The code @kunal.sachdev wrote looks exactly right to me, so I suspect core broke us. Or something. Anyway - I'll handle it.

chrisfromredfin’s picture

Issue tags: +core-mvp, +beta blocker

narendrar made their first commit to this issue’s fork.

narendrar’s picture

Status: Needs work » Needs review
phenaproxima’s picture

Assigned: phenaproxima » Unassigned
Status: Needs review » Reviewed & tested by the community

Ship it.

chrisfromredfin’s picture

Status: Reviewed & tested by the community » Fixed

done. Kernel test did fail, then pass on re-run. 🤷

narendrar’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.