{"record":{"id":"7e6f743f76302a0b","repo":"django/django","slug":"compilemessages-generated-one-or-more-errors","errorCode":null,"errorMessage":"compilemessages generated one or more errors.","messagePattern":"compilemessages generated one or more errors\\.","errorType":"console","errorClass":"CommandError","httpStatus":null,"severity":"error","filePath":"django/core/management/commands/compilemessages.py","lineNumber":140,"sourceCode":"        self.has_errors = False\n        for basedir in basedirs:\n            if locales:\n                dirs = [\n                    os.path.join(basedir, locale, \"LC_MESSAGES\") for locale in locales\n                ]\n            else:\n                dirs = [basedir]\n            locations = []\n            for ldir in dirs:\n                for dirpath, dirnames, filenames in os.walk(ldir):\n                    locations.extend(\n                        (dirpath, f) for f in filenames if f.endswith(\".po\")\n                    )\n            if locations:\n                self.compile_messages(locations)\n\n        if self.has_errors:\n            raise CommandError(\"compilemessages generated one or more errors.\")\n\n    def compile_messages(self, locations):\n        \"\"\"\n        Locations is a list of tuples: [(directory, file), ...]\n        \"\"\"\n        with concurrent.futures.ThreadPoolExecutor() as executor:\n            futures = []\n            for i, (dirpath, f) in enumerate(locations):\n                po_path = Path(dirpath) / f\n                mo_path = po_path.with_suffix(\".mo\")\n                try:\n                    if mo_path.stat().st_mtime >= po_path.stat().st_mtime:\n                        if self.verbosity > 0:\n                            self.stdout.write(\n                                \"File “%s” is already compiled and up to date.\"\n                                % po_path\n                            )\n                        continue","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/django/django/blob/ae25a40be07e8a749edf526df37c93e59d4a22c9/django/core/management/commands/compilemessages.py#L122-L158","documentation":"Raised by compilemessages (django/core/management/commands/compilemessages.py:140) as a CommandError at the end of processing when self.has_errors is True. The flag is set inside compile_messages when the msgfmt subprocess (run via popen_wrapper with --check-format) reports errors for one or more .po files. This is an aggregate failure: individual file errors are printed first, then this wraps them.","triggerScenarios":"Running compilemessages when one or more .po files contain syntax errors, invalid gettext format strings, mismatched printf-style placeholders between msgid and msgstr, or encoding issues that msgfmt --check-format rejects.","commonSituations":"Editing .po files by hand and breaking syntax; translations with wrong plural-form headers; %s/%d placeholder count mismatch between source and translation; BOM or encoding problems in the .po file; partial machine translation output.","solutions":["Read the per-file errors printed before this message; each names the .po file and the msgfmt complaint.","Open the offending .po file and fix the syntax/placeholder mismatch; ensure msgid and msgstr placeholders (%s, %d, %(...)s) match exactly.","Validate plural-forms header (Content-Type, plural forms) for the locale.","Re-run makemessages to regenerate a clean .po, then re-apply translations carefully."],"exampleFix":"# before (in .po)\nmsgid \"Welcome %s\"\nmsgstr \"Bienvenue %d\"   # placeholder mismatch\n# after\nmsgid \"Welcome %s\"\nmsgstr \"Bienvenue %s\"","handlingStrategy":"try-catch","validationCode":"# validate .po placeholder parity before compiling\nimport re, polib  # third-party\ndef check_placeholders(po_path):\n    for entry in polib.pofile(po_path):\n        if re.findall(r'%\\(.+?\\)[sd]', entry.msgid) != re.findall(r'%\\(.+?\\)[sd]', entry.msgstr):\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"from django.core.management.base import CommandError\ntry:\n    call_command('compilemessages')\nexcept CommandError:\n    # individual file errors were already printed; surface them in CI logs\n    raise","preventionTips":["Lint .po files (e.g. with polib) in CI to catch placeholder/parity errors before compilemessages.","Prefer makemessages regeneration over hand-editing .po files."],"tags":["django","i18n","gettext","validation","translations"],"analyzedSha":"ae25a40be07e8a749edf526df37c93e59d4a22c9","analyzedAt":"2026-08-06T21:46:51.801Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}