{"record":{"id":"2d3e398f7f40e9c3","repo":"3b1b/manim","slug":"no-class-found-above-line-number","errorCode":null,"errorMessage":"No 'class' found above {line_number}!","messagePattern":"No 'class' found above (.+?)!","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"manimlib/extract_scene.py","lineNumber":173,"sourceCode":"\n    # Add the relevant embed line to the code\n    indent = get_indent(lines, line_number)\n    lines.insert(line_number, indent + \"self.embed()\")\n    new_code = \"\\n\".join(lines)\n\n    # When the user executes the `-e <line_number>` command\n    # without specifying scene_names, the nearest class name above\n    # `<line_number>` will be automatically used as 'scene_names'.\n\n    if not run_config.scene_names:\n        classes = list(filter(lambda line: line.startswith(\"class\"), lines[:line_number]))\n        if classes:\n            from re import search\n\n            scene_name = search(r\"(\\w+)\\(\", classes[-1])\n            run_config.update(scene_names=[scene_name.group(1)])\n        else:\n            log.error(f\"No 'class' found above {line_number}!\")\n\n    # Execute the code, which presumably redefines the user's\n    # scene to include this embed line, within the relevant module.\n    code_object = compile(new_code, module.__name__, 'exec')\n    exec(code_object, module.__dict__)\n\n\ndef get_module(run_config: Dict) -> Module:\n    module = ModuleLoader.get_module(run_config.file_name, run_config.is_reload)\n    if run_config.embed_line:\n        insert_embed_line_to_module(module, run_config)\n    return module\n\n\ndef main(scene_config: Dict, run_config: Dict):\n    module = get_module(run_config)\n    all_scene_classes = get_scene_classes(module)\n    scenes = get_scenes_to_render(all_scene_classes, scene_config, run_config)","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/3b1b/manim/blob/dee01804d47b9f94402d71472674710dcac125b8/manimlib/extract_scene.py#L155-L191","documentation":"With the -e <line_number> option, manim injects an embed() call at that line; when no scene names were given, it scans backwards through the file's lines for the nearest top-level 'class ' statement to infer the containing scene. If no line above the given line starts with 'class', it logs 'No 'class' found above {line_number}!' and cannot infer the scene name.","triggerScenarios":"Running manim file.py -e 5 where line 5 precedes any class definition; pointing -e at a line inside module-level helper functions at the top of the file; files where the class line is indented or uses a decorator-only header.","commonSituations":"Trying to embed very early in a file to debug setup code; running -e against a script organized with imports/constants before any Scene subclass; line-number drift after edits (the number now points above the class).","solutions":["Point -e at a line at or below the class definition of the scene you want, e.g. inside construct()","Or name the scene explicitly so no inference is needed: manim file.py MyScene -e 42","Re-check the line number after editing the file — it refers to the current file's lines"],"exampleFix":"# before\n$ manim file.py -e 3        # line 3 is above 'class MyScene'\n# after\n$ manim file.py MyScene -e 10  # line 10 is inside MyScene.construct","handlingStrategy":"validation","validationCode":"with open(path) as f:\n    lines = f.readlines()\nassert any(l.startswith(\"class\") for l in lines[:embed_line]), \"no class above the embed line\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Point -e at a line inside construct() of the scene you're debugging","Also pass the scene name (manim file.py Scene -e N) so manim doesn't need to infer it","Re-verify line numbers after editing — they shift with every inserted/deleted line"],"tags":["cli","embed","debugging","scene-selection"],"backgroundTag":null,"analyzedSha":"dee01804d47b9f94402d71472674710dcac125b8","analyzedAt":"2026-08-14T19:53:44.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}