{"record":{"id":"4c801e57e5ae8c41","repo":"ansible/ansible","slug":"unexpected-error","errorCode":null,"errorMessage":"Unexpected error:","messagePattern":"Unexpected error:","errorType":"exception","errorClass":"CronTabError","httpStatus":null,"severity":"error","filePath":"lib/ansible/modules/cron.py","lineNumber":277,"sourceCode":"                self.b_cron_file = os.path.join(b'/etc/cron.d', to_bytes(cron_file, errors='surrogate_or_strict'))\n        else:\n            self.cron_file = None\n\n        self.read()\n\n    def read(self):\n        # Read in the crontab from the system\n        if self.cron_file:\n            # read the cronfile\n            try:\n                with open(self.b_cron_file, 'rb') as f:\n                    self.n_existing = to_native(f.read(), errors='surrogate_or_strict')\n                    self.lines = self.n_existing.splitlines()\n            except OSError:\n                # cron file does not exist\n                return\n            except Exception:\n                raise CronTabError(\"Unexpected error:\", sys.exc_info()[0])\n        else:\n            # FIXME: using safely quoted shell for now, but this really should be two non-shell calls instead.\n            (rc, out, err) = self.module.run_command(self._read_user_execute(), use_unsafe_shell=True)\n\n            if rc not in (0, 1):  # 1 can mean that there are no jobs.\n                raise CronTabError(\"Unable to read crontab\")\n\n            self.n_existing = out\n\n            lines = out.splitlines()\n            count = 0\n            for l in lines:\n                if count > 2 or (not re.match(r'# DO NOT EDIT THIS FILE - edit the master and reinstall.', l) and\n                                 not re.match(r'# \\(/tmp/.*installed on.*\\)', l) and\n                                 not re.match(r'# \\(.*version.*\\)', l)):\n                    self.lines.append(l)\n                else:\n                    pattern = re.escape(l) + '[\\r\\n]?'","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/ansible/ansible/blob/9cf16a4aca7898481c257f1e17ad28d0b67b1f85/lib/ansible/modules/cron.py#L259-L295","documentation":"Error \"Unexpected error:\" thrown in ansible/ansible.","triggerScenarios":"Thrown at lib/ansible/modules/cron.py:277 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Run with -vvv to see the underlying cron error.","Check that cron is installed and the user has permission to edit crontabs."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9cf16a4aca7898481c257f1e17ad28d0b67b1f85","analyzedAt":"2026-08-15T00:15:47.100Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}