{"record":{"id":"182382ffad92f38c","repo":"Aider-AI/aider","slug":"no-filename-provided-before-self-fence-0-in-fil","errorCode":null,"errorMessage":"No filename provided before {self.fence[0]} in file listing","messagePattern":"No filename provided before (.+?) in file listing","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"aider/coders/wholefile_coder.py","lineNumber":82,"sourceCode":"                    # Issue #1232\n                    if len(fname) > 250:\n                        fname = \"\"\n\n                    # Did gpt prepend a bogus dir? It especially likes to\n                    # include the path/to prefix from the one-shot example in\n                    # the prompt.\n                    if fname and fname not in chat_files and Path(fname).name in chat_files:\n                        fname = Path(fname).name\n                if not fname:  # blank line? or ``` was on first line i==0\n                    if saw_fname:\n                        fname = saw_fname\n                        fname_source = \"saw\"\n                    elif len(chat_files) == 1:\n                        fname = chat_files[0]\n                        fname_source = \"chat\"\n                    else:\n                        # TODO: sense which file it is by diff size\n                        raise ValueError(\n                            f\"No filename provided before {self.fence[0]} in file listing\"\n                        )\n\n            elif fname is not None:\n                new_lines.append(line)\n            else:\n                for word in line.strip().split():\n                    word = word.rstrip(\".:,;!\")\n                    for chat_file in chat_files:\n                        quoted_chat_file = f\"`{chat_file}`\"\n                        if word == quoted_chat_file:\n                            saw_fname = chat_file\n\n                output.append(line)\n\n        if mode == \"diff\":\n            if fname is not None:\n                # ending an existing block","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/Aider-AI/aider/blob/5dc9490bb35f9729ef2c95d00a19ccd30c26339c/aider/coders/wholefile_coder.py#L64-L100","documentation":"WholefileCoder error while splitting a model reply into files: a fenced code block was encountered but no filename could be determined for it. The coder tries the last seen filename, then a single-file fallback (chat_files having exactly one entry); with neither available it raises.","triggerScenarios":"Model returns a bare ``` fence with no preceding filename mention while zero or 2+ files are in chat; the filename word appears after the fence instead of before; filename formatting differs from the backtick-quoted chat-file matching.","commonSituations":"Using wholefile coder with an empty chat and asking for new-file output; model says 'I'll write the code:' followed by an anonymous fence; filename mentioned in prose without backticks so saw_fname never gets set.","solutions":["Add exactly one file to chat so the single-file fallback applies, or mention the target filename in backticks (e.g. `foo.py`) before the fence","Switch the edit format (e.g. diff/udiff or patch format) where filenames are explicit per hunk","Prompt the model to label every code block with its filename"],"exampleFix":"# before (model reply)\nHere is the code:\n```python\ndef f(): ...\n```\n\n# after\nHere is `foo.py`:\n```python\ndef f(): ...\n```\n","handlingStrategy":"validation","validationCode":"def fence_has_filename(reply: str, chat_files: list[str]) -> bool:\n    fence = reply.split(\"```\")\n    # odd indices are inside fences; check text before each opening fence\n    for i in range(1, len(fence), 2):\n        preceding = fence[i - 1]\n        mentioned = any(f in preceding for f in chat_files)\n        if not mentioned and len(chat_files) != 1:\n            return False\n    return True","typeGuard":null,"tryCatchPattern":"try:\n    edited = coder.get_edits(reply)\nexcept ValueError as e:\n    if \"No filename provided before\" in str(e):\n        reply = f\"`{chat_files[0]}`\\n\" + reply if len(chat_files) == 1 else reply\n        edited = coder.get_edits(reply)\n    else:\n        raise","preventionTips":["With wholefile coder, keep exactly one file in chat or name files in backticks before each fence","Prompt the model to label every code block with its filename","Prefer the diff/patch edit formats for multi-file changes — filenames are explicit"],"tags":["aider","wholefile-coder","parsing","filename"],"backgroundTag":null,"analyzedSha":"5dc9490bb35f9729ef2c95d00a19ccd30c26339c","analyzedAt":"2026-08-15T05:40:10.498Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}