{"record":{"id":"7b1abc19e1a6f0e3","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-locate-program-executable-on-the-pat","errorCode":null,"errorMessage":"Failed to locate '{program}' executable on the path.","messagePattern":"Failed to locate '(.+?)' executable on the path\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Core/EnvironmentBase.cs","lineNumber":193,"sourceCode":"        protected abstract IReadOnlyDictionary<string, string> GetCurrentVariables();\n    }\n\n    public static class EnvironmentExtensions\n    {\n        /// <summary>\n        /// Locate an executable on the current PATH.\n        /// </summary>\n        /// <param name=\"environment\">The <see cref=\"IEnvironment\"/>.</param>\n        /// <param name=\"program\">Executable program name.</param>\n        /// <returns>List of all instances of the found executable program, in order of most specific to least.</returns>\n        public static string LocateExecutable(this IEnvironment environment, string program)\n        {\n            if (environment.TryLocateExecutable(program, out string path))\n            {\n                return path;\n            }\n\n            throw new Exception($\"Failed to locate '{program}' executable on the path.\");\n        }\n\n        /// <summary>\n        /// Retrieves the value of an environment variable from the current process.\n        /// </summary>\n        /// <param name=\"environment\">The <see cref=\"IEnvironment\"/>.</param>\n        /// <param name=\"variable\">The name of the environment variable.</param>\n        /// <returns>\n        /// The value of the environment variable specified by variable, or null if the environment variable is not found.\n        /// </returns>\n        public static string GetEnvironmentVariable(this IEnvironment environment, string variable)\n        {\n            return environment.Variables.TryGetValue(variable, out string value) ? value : null;\n        }\n    }\n}\n","sourceCodeStart":175,"sourceCodeEnd":210,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/EnvironmentBase.cs#L175-L210","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar gitPath = environment.LocateExecutable(\"git\"); // throws if git missing\n// after\nif (environment.TryLocateExecutable(\"git\", out string gitPath))\n{\n    // use gitPath\n}\nelse\n{\n    Console.Error.WriteLine(\"Git was not found on PATH. Install Git or add it to PATH.\");\n}","handlingStrategy":"fallback","validationCode":"if (!environment.TryLocateExecutable(program, out string path))\n{\n    Console.Error.WriteLine($\"'{program}' not found on PATH. Install it or update PATH.\");\n    return null;\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    path = LocateExecutable(program);\n}\ncatch (Exception ex)\n{\n    logger.LogError(ex, $\"Executable '{program}' was not found on PATH.\");\n    // fail gracefully or fall back to an explicit install path\n}","preventionTips":["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."],"tags":["executable","path","environment","process-startup"],"backgroundTag":"command-not-found","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}