{"record":{"id":"7d16f3d867b152a2","repo":"dotnet/runtime","slug":"error-toc-file-not-created-correctly-at-s","errorCode":null,"errorMessage":"Error, toc file not created correctly at: %s","messagePattern":"Error, toc file not created correctly at: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/coreclr/scripts/superpmi.py","lineNumber":1463,"sourceCode":"        if not self.coreclr_args.skip_cleanup:\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 __create_toc__(self):\n        \"\"\" Create a TOC file\n\n        Notes:\n            <mcl> -toc <s_finalMchFile>\n        \"\"\"\n\n        logging.info(\"Creating TOC file\")\n\n        command = [self.mcs_path, \"-toc\", self.final_mch_file]\n        run_and_log(command)\n\n        if not os.path.isfile(self.toc_file):\n            raise RuntimeError(\"Error, toc file not created correctly at: %s\" % self.toc_file)\n\n    def __verify_final_mch__(self):\n        \"\"\" Verify the resulting MCH file is error-free when running SuperPMI against it with the same JIT used for collection.\n\n        Notes:\n            <SuperPmiPath> -p -f <s_finalFailMclFile> <s_finalMchFile> <jitPath>\n        \"\"\"\n\n        logging.info(\"Verifying MCH file\")\n\n        mch_files = [ self.final_mch_file ]\n        spmi_replay = SuperPMIReplay(self.coreclr_args, mch_files, self.jit_path)\n        passed = spmi_replay.replay()\n\n        if not passed:\n            raise RuntimeError(\"Error, unclean replay.\")\n\n    def __process_for_ci__(self):","sourceCodeStart":1445,"sourceCodeEnd":1481,"githubUrl":"https://github.com/dotnet/runtime/blob/60108ba66eb7d1d12f595480091b4ad80a24b172/src/coreclr/scripts/superpmi.py#L1445-L1481","documentation":"Raised by SuperPMICollection.__create_toc__ after it invokes the 'mcs' tool (machine-code-source) with the -toc flag on the final MCH file. The function then checks for the existence of a Table-of-Contents file derived from the MCH path; if mcs did not produce it, the collection is considered corrupt or incomplete and the run aborts. The TOC is required for merge and replay operations to index method contexts inside the MCH.","triggerScenarios":"Called during collection finalization: command = [self.mcs_path, '-toc', self.final_mch_file]; run_and_log(command) runs mcs, then os.path.isfile(self.toc_file) is False. Happens when mcs crashes or returns nonzero without writing the TOC, when the MCH file is zero-length or corrupt, when mcs_path points to the wrong binary, or when the TOC path derivation does not match what mcs actually writes.","commonSituations":"An mcs binary from a mismatched/incompatible runtime build; a corrupt or empty MCH file produced by a failed collection (e.g. the target process never JIT-compiled anything); running on a cross-arch target where the mcs binary cannot parse the native MCH; disk-full or permission denied on the spmi_location output directory.","solutions":["Re-run mcs manually on the MCH file to see its stderr/exit code: '<mcs_path> -toc <final_mch_file>' and inspect any error output.","Verify the MCH file is non-empty and not corrupt (check file size and, if possible, open with mcs -stat).","Ensure the mcs binary matches the JIT-EE version and architecture of the collected MCH (use the mcs from the same build/Core_Root).","Confirm write permission and free space in the directory that should contain toc_file."],"exampleFix":"// before\ncommand = [self.mcs_path, \"-toc\", self.final_mch_file]\nrun_and_log(command)\nif not os.path.isfile(self.toc_file):\n    raise RuntimeError(\"Error, toc file not created correctly at: %s\" % self.toc_file)\n// after\ncommand = [self.mcs_path, \"-toc\", self.final_mch_file]\nreturn_code = run_and_log(command)\nif return_code != 0 or not os.path.isfile(self.toc_file):\n    raise RuntimeError(f\"mcs -toc failed (code {return_code}); toc file not created at: {self.toc_file}\")","handlingStrategy":"validation","validationCode":"import os, subprocess\ndef verify_toc_will_succeed(mcs_path, final_mch_file, toc_file):\n    if not os.path.isfile(mcs_path):\n        raise RuntimeError(f\"mcs tool not found: {mcs_path}\")\n    if not os.path.isfile(final_mch_file) or os.path.getsize(final_mch_file) == 0:\n        raise RuntimeError(f\"MCH file missing or empty: {final_mch_file}\")\n    toc_dir = os.path.dirname(toc_file)\n    if not os.path.isdir(toc_dir) or not os.access(toc_dir, os.W_OK):\n        raise RuntimeError(f\"TOC target directory missing or not writable: {toc_dir}\")\n    rc = subprocess.run([mcs_path, '-toc', final_mch_file]).returncode\n    if rc != 0:\n        raise RuntimeError(f\"mcs -toc exited with code {rc}\")","typeGuard":null,"tryCatchPattern":"try:\n    __create_toc__(self)\nexcept RuntimeError as e:\n    logging.error(\"TOC creation failed: %s\", e)\n    logging.error(\"Inspect MCH with: %s -stat %s\", self.mcs_path, self.final_mch_file)\n    raise","preventionTips":["Use an mcs binary built from the same runtime version as the collected MCH.","Validate the MCH file is non-empty before creating the TOC.","Run mcs -stat on the MCH to confirm it is parseable before -toc."],"tags":["superpmi","mcs","toc","collection","mch"],"backgroundTag":null,"analyzedSha":"60108ba66eb7d1d12f595480091b4ad80a24b172","analyzedAt":"2026-08-10T18:54:11.478Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}