fix: fail fast when package manager is not installed (#360)

* fix: fail fast with clear error when package manager is not installed

When PMG shims intercept a package manager that isn't installed (e.g. a
clean JAMF-provisioned laptop where PMG is set up before dev tooling),
real-binary resolution failed with a generic "unknown" error and a
bug-report link, making it look like PMG itself had crashed.

Introduce a typed BinaryNotFoundError that exits with code 127 (standard
"command not found") and maps to a new PackageManagerNotFound error code
with an actionable message instead of the Unknown classification.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: improve missing package manager help message

Use a concise, dynamic install hint instead of explaining PMG's
PATH forwarding internals.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix: mention PATH in missing package manager help text

Covers the common case where a package manager is installed but its bin
directory is not on PATH yet (e.g. after curl | bash install).

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Sahil Bansal
2026-07-06 18:31:18 +05:30
committed by GitHub
co-authored by Cursor
parent b19473945b
commit 02965143d0
11 changed files with 124 additions and 0 deletions
+17
View File
@@ -13,6 +13,7 @@ import (
"github.com/safedep/dry/usefulerror"
"github.com/safedep/pmg/errcodes"
"github.com/safedep/pmg/internal/shim"
)
// errorMatcher defines how to detect and convert a specific error type
@@ -24,6 +25,22 @@ type errorMatcher struct {
// errorMatchers is an ordered list of error matchers
// Order matters - more specific matchers should come first
var errorMatchers = []errorMatcher{
// Package manager not installed (PMG shim hit, real binary absent from PATH).
{
match: func(err error) bool {
var notFound *shim.BinaryNotFoundError
return errors.As(err, &notFound)
},
convert: func(err error) usefulerror.UsefulError {
var notFound *shim.BinaryNotFoundError
errors.As(err, &notFound)
return usefulerror.NewUsefulError().
WithCode(errcodes.PackageManagerNotFound).
WithHumanError(fmt.Sprintf("%s is not installed", notFound.Name)).
WithHelp(fmt.Sprintf("Install %s and ensure it is on your PATH, then retry.", notFound.Name)).
Wrap(notFound)
},
},
// File not found errors
{
match: func(err error) bool {