git-ecosystem/git-credential-manager · error · Exception
Failed to locate ' ' executable on the path.
Error message
Failed to locate '{program}' executable on the path. What it means
EnvironmentBase.LocateExecutable wraps IEnvironment.TryLocateExecutable, which searches the PATH for a program's executable. If the search fails to find a matching executable file, it throws a plain Exception rather than returning a path. This guards callers from receiving a null/empty path and forces them to handle a missing external dependency explicitly.
Solutions
- Install the required program (e.g. Git) or add its install directory to the PATH environment variable before starting the host process.
- Verify with `where <program>` (Windows) or `which <program>` (Unix) that the executable resolves in the same environment the app runs in.
- If PATH differs per account/service, set the PATH explicitly in the service/CI configuration or pass an absolute path instead of relying on LocateExecutable.
- Catch the exception and surface a user-facing message instructing how to install/locate the program.
Example fix
// before
var gitPath = environment.LocateExecutable("git"); // throws if git missing
// after
if (environment.TryLocateExecutable("git", out string gitPath))
{
// use gitPath
}
else
{
Console.Error.WriteLine("Git was not found on PATH. Install Git or add it to PATH.");
} Defensive patterns
Strategy: fallback
Validate before calling
if (!environment.TryLocateExecutable(program, out string path))
{
Console.Error.WriteLine($"'{program}' not found on PATH. Install it or update PATH.");
return null;
} Try / catch
try
{
path = LocateExecutable(program);
}
catch (Exception ex)
{
logger.LogError(ex, $"Executable '{program}' was not found on PATH.");
// fail gracefully or fall back to an explicit install path
} Prevention
- Verify executables with `where`/`which` in the exact environment (CI, service account) before running.
- Pin known install locations and check File.Exists on them before PATH lookup.
- Include PATH diagnostics in startup logging.
- Document required external dependencies (Git) in installation instructions.
When it happens
Trigger: Calling EnvironmentBase.LocateExecutable("git") (or any program name) when the executable is not present in any directory listed on the PATH environment variable, or when TryLocateExecutable cannot resolve it on the current platform.
Common situations: Git is not installed or not on PATH in CI containers, minimal Docker images, or service accounts whose PATH differs from the interactive user's; running on Windows where Git was installed with a portable/unregistered copy; PATH modified after process start.
Related errors
- Unable to persist credentials with the
- GPG_TTY is not set; add `export GPG_TTY=$(tty)` to your…
- GPG executable does not exist with path
- Failed to start gpg.
- Failed to locate a utility to launch the default web…
AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11).
Data as JSON: /api/errors/7b1abc19e1a6f0e3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Core/EnvironmentBase.cs:193
protected abstract IReadOnlyDictionary<string, string> GetCurrentVariables();
}
public static class EnvironmentExtensions
{
/// <summary>
/// Locate an executable on the current PATH.
/// </summary>
/// <param name="environment">The <see cref="IEnvironment"/>.</param>
/// <param name="program">Executable program name.</param>
/// <returns>List of all instances of the found executable program, in order of most specific to least.</returns>
public static string LocateExecutable(this IEnvironment environment, string program)
{
if (environment.TryLocateExecutable(program, out string path))
{
return path;
}
throw new Exception($"Failed to locate '{program}' executable on the path.");
}
/// <summary>
/// Retrieves the value of an environment variable from the current process.
/// </summary>
/// <param name="environment">The <see cref="IEnvironment"/>.</param>
/// <param name="variable">The name of the environment variable.</param>
/// <returns>
/// The value of the environment variable specified by variable, or null if the environment variable is not found.
/// </returns>
public static string GetEnvironmentVariable(this IEnvironment environment, string variable)
{
return environment.Variables.TryGetValue(variable, out string value) ? value : null;
}
}
}
View on GitHub (pinned to e8ce762cd0)