unoplatform/uno · error · InvalidOperationException

git {arguments} failed: {error}

Error message

git {arguments} failed: {error}

What it means

After git exits, RunGit checks the exit code; any non-zero result is surfaced by reading stderr and throwing an InvalidOperationException whose message embeds both the failing command line and git's own error text. The real cause lives inside that captured stderr string (network failure, unknown ref, auth rejection, etc.).

Source

Thrown at src/FontFallbackPreprocessor/Program.cs:800

	private static void RunGit(string arguments)
	{
		var processStart = new ProcessStartInfo
		{
			FileName = "git",
			Arguments = arguments,
			CreateNoWindow = true,
			UseShellExecute = false,
			RedirectStandardError = true,
			RedirectStandardOutput = true
		};

		using var process = Process.Start(processStart) ?? throw new InvalidOperationException("Failed to start git process.");
		process.WaitForExit();

		if (process.ExitCode != 0)
		{
			var error = process.StandardError.ReadToEnd();
			throw new InvalidOperationException($"git {arguments} failed: {error}");
		}
	}
}

View on GitHub (pinned to 0418340488)

Solutions

  1. Read the embedded stderr in the exception message — it names the exact git failure (e.g. 'fatal: could not read Username', 'error: pathspec ... did not match').
  2. For auth issues, provide credentials via a credential helper, GIT_ASKPASS, or a token in the remote URL for private repos.
  3. For network issues, verify connectivity to github.com and configure HTTP_PROXY/HTTPS_PROXY if behind a proxy.
  4. Confirm the branch/repo/sparse path in the preprocessor config actually exist on the remote.
  5. Upgrade git to >= 2.25 if sparse/filter flags are rejected; fall back to a full shallow clone otherwise.
  6. If the repo is already cloned and only fetch fails, retry — transient GitHub outages and rate limits resolve on backoff.

Example fix

// before
throw new InvalidOperationException($"git {arguments} failed: {error}");

// after — keep the message, but also surface exit code for triage
throw new InvalidOperationException($"git {arguments} failed (exit {process.ExitCode}): {error.Trim()}");
Defensive patterns

Strategy: retry

Validate before calling

// Validate inputs before invoking git
static void ValidateCloneTarget(string repo, string branch)
{
    if (string.IsNullOrWhiteSpace(repo) || !repo.Contains('/'))
        throw new ArgumentException($"Invalid repo spec: {repo}");
    if (string.IsNullOrWhiteSpace(branch))
        throw new ArgumentException("Branch must be specified.");
}

Try / catch

// Retry transient network failures, surface auth/branch errors immediately
int attempts = 0;
while (true)
{
    try { RunGit(arguments); break; }
    catch (InvalidOperationException ex) when (IsTransient(ex.Message) && attempts++ < 3)
    { Thread.Sleep(TimeSpan.FromSeconds(2 * attempts)); continue; }
}

Prevention

When it happens

Trigger: git clone/fetch/checkout/sparse-checkout/reset returns non-zero: nonexistent branch or tag, private repo without credentials, network timeout or DNS failure, GitHub rate limiting, a dirty working tree blocking `reset --hard`, or a git version too old to understand `--filter=blob:none --sparse` (needs git >= 2.25).

Common situations: Corporate proxy or firewall blocking github.com; expired/missing GitHub auth token for a private font repo; typo'd branch name in the preprocessor config; offline build attempting a fresh clone; shallow+sparse clone flags rejected by an older git; GitHub rate limit during heavy CI.

Related errors


AI-assisted analysis of unoplatform/uno@0418340488 (2026-08-13). Data as JSON: /api/errors/a6addc9ae5972339. Report an issue: GitHub.