ungoogled-software/ungoogled-chromium · error · RuntimeError

Got non-zero exit code running "{' '.join(cmd)}"

Error message

Got non-zero exit code running "{' '.join(cmd)}"

What it means

find_and_check_patch runs the external `patch` binary via subprocess and raises RuntimeError when it exits with a non-zero status. The library logs stdout/stderr first, so the RuntimeError wraps an underlying patch-tool failure (bad patch file, wrong tree, missing binary behavior differences). It indicates the patch command itself failed, not a Python-side bug.

Source

Thrown at utils/patches.py:76

        patch_bin_path = _find_patch_from_which()
    if not patch_bin_path:
        raise ValueError('Could not find patch from PATCH_BIN env var or "which patch"')

    if not patch_bin_path.exists():
        raise ValueError(f'Could not find the patch binary: {patch_bin_path}')

    # Ensure patch actually runs
    cmd = [str(patch_bin_path), '--version']
    result = subprocess.run(cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            check=False,
                            universal_newlines=True)
    if result.returncode:
        get_logger().error('"%s" returned non-zero exit code', ' '.join(cmd))
        get_logger().error('stdout:\n%s', result.stdout)
        get_logger().error('stderr:\n%s', result.stderr)
        raise RuntimeError(f"Got non-zero exit code running \"{' '.join(cmd)}\"")

    return patch_bin_path


def dry_run_check(patch_path, tree_path, patch_bin_path=None):
    """
    Run patch --dry-run on a patch

    tree_path is the pathlib.Path of the source tree to patch
    patch_path is a pathlib.Path to check
    reverse is whether the patches should be reversed
    patch_bin_path is the pathlib.Path of the patch binary, or None to find it automatically
        See find_and_check_patch() for logic to find "patch"

    Returns the status code, stdout, and stderr of patch --dry-run
    """
    cmd = [
        str(find_and_check_patch(patch_bin_path)), '-p1', '--ignore-whitespace', '-i',

View on GitHub (pinned to f85e84a480)

Solutions

  1. Read the logged stdout/stderr above the traceback to see the actual `patch` failure reason
  2. Re-run with a clean checkout of the target tree to undo partial application
  3. Verify the patch file matches the tree version (regenerate or update the patch series)
  4. Check patch_bin_path resolves to a working `patch` binary (e.g. `patch --version`)
  5. Use dry_run_check first to catch apply failures before mutating the tree

Example fix

# before
apply_patches(tree, patches)  # may raise RuntimeError mid-apply
# after
dry_run_check(tree, patches)  # validate first
apply_patches(tree, patches)
Defensive patterns

Strategy: try-catch

Validate before calling

import shutil
from utils.patches import dry_run_check
if shutil.which(patch_bin_path or 'patch') is None:
    raise SystemExit('patch binary not available')
dry_run_check(patch_path, tree_path, patch_bin_path)  # fail before mutating

Type guard

def patch_binary_available(path):
    return isinstance(path, (str, type(None))) and (path is None or shutil.which(path) is not None)

Try / catch

try:
    apply_patches(tree, patches)
except RuntimeError as e:
    logger.exception('patch command failed: %s', e)
    restore_clean_tree(tree)  # e.g. git checkout / re-extract

Prevention

When it happens

Trigger: Calling find_and_check_patch (directly or via dry_run_check / apply_patches) when the `patch` command returns non-zero: patch file doesn't apply to the target tree, malformed/unified diff mismatch, patch already applied (reversed), or patch_bin_path points to a broken/nonexistent binary wrapper.

Common situations: Kernel/source tree updated so hunks no longer match; running apply_patches twice on the same tree; wrong tree_path passed; distro `patch` variant with different flags; dry-run check failing before real apply.

Related errors


AI-assisted analysis of ungoogled-software/ungoogled-chromium@f85e84a480 (2026-08-29). Data as JSON: /api/errors/989e7f3c0592c215. Report an issue: GitHub.