{"record":{"id":"2d88ce50717d5f86","repo":"nwjs/nw.js","slug":"d-patches-failed-to-apply-your-build-will-not-be","errorCode":null,"errorMessage":"%d patches failed to apply. Your build will not be correct.","messagePattern":"(.+?) patches failed to apply\\. Your build will not be correct\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"tools/patcher.py","lineNumber":95,"sourceCode":"    if dopatch:\n      result = apply_patch_file(patch_file, patch['path']\n                                if 'path' in patch else None)\n      results[result] += 1\n\n      if 'note' in patch:\n        write_note('NOTE', patch['note'])\n    else:\n      results['skip'] += 1\n\n  sys.stdout.write('\\n%d patches total (%d applied, %d skipped, %d failed)\\n' % \\\n      (len(patches), results['apply'], results['skip'], results['fail']))\n\n  if results['fail'] > 0:\n    sys.stdout.write('\\n')\n    write_note('ERROR',\n               '%d patches failed to apply. Your build will not be correct.' %\n               results['fail'])\n    raise Exception(\n        '%d patches failed to apply. Your build will not be correct.' %\n        results['fail'])\n\n\n# Parse command-line options.\ndisc = \"\"\"\nThis utility applies patch files.\n\"\"\"\n\nparser = OptionParser(description=disc)\nparser.add_option(\n    '--patch-file', dest='patchfile', metavar='FILE', help='patch source file')\nparser.add_option(\n    '--patch-dir',\n    dest='patchdir',\n    metavar='DIR',\n    help='patch target directory')\n# NWJS: Path of config file has been hard-coded in this script, so this option","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/tools/patcher.py#L77-L113","documentation":"Raised by apply_patch_config() in tools/patcher.py after the loop over patches completes, when results['fail'] > 0. Each patch is applied via git_apply_patch_file; if any return 'fail', the build is considered incorrect because the Chromium source tree will be in a partially-patched state. The exception halts the build to prevent shipping a broken binary.","triggerScenarios":"A patch in patch.cfg no longer applies cleanly against the checked-out Chromium revision (context mismatch, already-applied hunk, conflicting upstream change); a patch file referenced by patch.cfg is missing from patch/patches/; line-ending or whitespace drift causing git apply to reject a hunk.","commonSituations":"Upgrading the Chromium revision without rebasing the NW.js patches; switching OS line endings (CRLF/LF) that confuse git apply; partial previous run leaving the tree half-patched so re-application conflicts; stale patch files after a branch switch.","solutions":["Inspect the per-patch 'This patch failed to apply' NOTE output above the summary to identify which patch(es) failed.","Rebase the offending .patch file against the current Chromium source: regenerate with git diff or manually fix context lines.","Reset the source tree to a clean state (git checkout . in the Chromium src dir) and re-run patcher to rule out a half-patched tree.","Verify the Chromium revision matches what the NW.js patches target (check DEPS / the pinned commit)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"import subprocess\n\ndef patch_applies_cleanly(patch_path, src_dir):\n    result = subprocess.run(['git', 'apply', '--check', patch_path], cwd=src_dir)\n    return result.returncode == 0","typeGuard":null,"tryCatchPattern":"try:\n    apply_patch_config()\nexcept Exception as e:\n    if 'patches failed to apply' in str(e):\n        # reset tree and rebase patches against current Chromium rev\n        subprocess.run(['git', 'checkout', '.'], cwd=src_dir)\n        raise SystemExit('Rebase failed patches against the current Chromium revision, then rebuild.')\n    raise","preventionTips":["Keep the Chromium revision in sync with what the NW.js patches target (check DEPS).","Reset the source tree to a clean state before re-running patcher to avoid half-patched conflicts.","Re-generate stale .patch files with git diff when rebasing onto a new Chromium version.","Watch line-ending settings (core.autocrlf) that can break git apply."],"tags":["nwjs","build","patcher","patch-conflict","git-apply","python"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}