{"record":{"id":"b24642666e7dd750","repo":"dotnet/runtime","slug":"final-mch-file-failed-to-be-generated","errorCode":null,"errorMessage":"Final mch file failed to be generated.","messagePattern":"Final mch file failed to be generated\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/coreclr/scripts/superpmi.py","lineNumber":1420,"sourceCode":"            else\n                # copy/move base file to final file\n            del <s_baseFailMclFile>\n        \"\"\"\n\n        logging.info(\"Cleaning MCH file\")\n\n        command = [self.superpmi_path, \"-p\", \"-f\", self.base_fail_mcl_file, self.base_mch_file, self.jit_path]\n        run_and_log(command)\n\n        if is_nonzero_length_file(self.base_fail_mcl_file):\n            command = [self.mcs_path, \"-strip\", self.base_fail_mcl_file, self.base_mch_file, self.final_mch_file]\n            run_and_log(command)\n        else:\n            # Ideally we could just rename this file instead of copying it.\n            shutil.copy2(self.base_mch_file, self.final_mch_file)\n\n        if not os.path.isfile(self.final_mch_file):\n            raise RuntimeError(\"Final mch file failed to be generated.\")\n\n        if not self.coreclr_args.skip_cleanup:\n            if os.path.isfile(self.base_fail_mcl_file):\n                os.remove(self.base_fail_mcl_file)\n                self.base_fail_mcl_file = None\n            if os.path.isfile(self.base_mch_file):\n                os.remove(self.base_mch_file)\n                self.base_mch_file = None\n\n    def __copy_to_final_mch_file__(self):\n        \"\"\" When not cleaning the MCH file, copy the base MCH file to the final MCH file location.\n\n        Notes:\n            # copy/move base file to final file\n            del <s_baseFailMclFile>\n        \"\"\"\n\n        logging.info(\"Copy base MCH file to final MCH file\")","sourceCodeStart":1402,"sourceCodeEnd":1438,"githubUrl":"https://github.com/dotnet/runtime/blob/290d5ab72cc1102813fbc0406fb186ceadabc340/src/coreclr/scripts/superpmi.py#L1402-L1438","documentation":"Raised in `__create_clean_mch_file__` (superpmi.py:1419-1420), taken when `--clean` is set. After running `superpmi -p` to find failing contexts and either `mcs -strip` or a `shutil.copy2` of base to final, it verifies final_mch_file exists; absence means the clean/strip step did not produce the final MCH. This is the 'clean' branch counterpart of the copy branch.","triggerScenarios":"Running collection with `--clean` where the strip (mcs -strip) or the base-to-final copy failed. Typical when base_mch_file itself is missing (merge failed earlier) or the strip command errored on the failing-context list.","commonSituations":"A prior merge step (error 164) silently left no base MCH, so the clean step has nothing to strip/copy; the base_fail_mcl_file path is invalid; disk/permission problems during copy2.","solutions":["Confirm the merge step (error 164) succeeded and base_mch_file exists before the clean step runs.","Inspect the `superpmi -p` and `mcs -strip` command output logged just before this error.","Re-run without `--clean` first to isolate whether the failure is in strip vs. plain copy."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"# Verify base_mch_file exists before the clean step runs\nif not os.path.isfile(base_mch_file):\n    raise SystemExit('base MCH missing; merge step must succeed before --clean.')","typeGuard":null,"tryCatchPattern":"try:\n    collection.__create_clean_mch_file__()\nexcept RuntimeError as e:\n    if 'Final mch file failed' in str(e):\n        logging.error('clean/strip did not produce final MCH; check superpmi -p / mcs -strip output.')\n    raise","preventionTips":["Ensure the merge step succeeded before enabling --clean.","Inspect superpmi -p output for the failing context list."],"tags":["mch","clean","superpmi","diagnostics"],"analyzedSha":"290d5ab72cc1102813fbc0406fb186ceadabc340","analyzedAt":"2026-08-06T19:57:01.276Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}