Skip to content

🚫 WhyNotPackage

Explains why a specific version of a package cannot be installed. Equivalent to composer why-not package/name version.

When to use

  • 🐛 When you hit a conflict while upgrading or pinning a version and need to locate which constraint blocks the installation.
  • 🔍 To evaluate whether a specific version can be introduced.
  • 📋 To explain the root cause of a version choice in a dependency review.

Signature

go
func (c *Composer) WhyNotPackage(packageName string, version string) (string, error)

Parameters

ParameterTypeDescription
packageNamestringName of the package to query
versionstringVersion to query, e.g. v4.0.0

Return value

ValueTypeDescription
OutputstringOutput of the explanation, listing the chain of constraints that block the installation
ErrorerrorReturned when an error occurs during the query

Example

go
package main

import (
    "fmt"
    "log"

    "github.com/scagogogo/composer-skills/pkg/composer"
)

func main() {
    comp, err := composer.New(composer.DefaultOptions())
    if err != nil {
        log.Fatalf("init failed: %v", err)
    }

    output, err := comp.WhyNotPackage("symfony/console", "v4.0.0")
    if err != nil {
        log.Fatalf("query version constraint failed: %v", err)
    }
    fmt.Println("reason it cannot be installed:", output)
}

Advanced

WhyNotWithOptions

Use this when you need to pass additional options (additional_methods.go):

go
func (c *Composer) WhyNotWithOptions(packageName, version string, options map[string]string) (string, error)

Forward question

Version format

version should be a version string Composer can recognize, such as v4.0.0, ^4.0, etc. Passing an invalid format may produce error output that is hard to interpret.

Released under the MIT License