{"record":{"id":"9a4955085fdc1394","repo":"3b1b/manim","slug":"dieface-only-accepts-integer-inputs-between-1-and","errorCode":null,"errorMessage":"DieFace only accepts integer inputs between 1 and 6","messagePattern":"DieFace only accepts integer inputs between 1 and 6","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"manimlib/mobject/svg/drawings.py","lineNumber":711,"sourceCode":"        stroke_color: ManimColor = WHITE,\n        stroke_width: float = 2.0,\n        fill_color: ManimColor = GREY_E,\n        dot_radius: float = 0.08,\n        dot_color: ManimColor = WHITE,\n        dot_coalesce_factor: float = 0.5\n    ):\n        dot = Dot(radius=dot_radius, fill_color=dot_color)\n        square = Square(\n            side_length=side_length,\n            stroke_color=stroke_color,\n            stroke_width=stroke_width,\n            fill_color=fill_color,\n            fill_opacity=1.0,\n        )\n        square.round_corners(corner_radius)\n\n        if not (1 <= value <= 6):\n            raise Exception(\"DieFace only accepts integer inputs between 1 and 6\")\n\n        edge_group = [\n            (ORIGIN,),\n            (UL, DR),\n            (UL, ORIGIN, DR),\n            (UL, UR, DL, DR),\n            (UL, UR, ORIGIN, DL, DR),\n            (UL, UR, LEFT, RIGHT, DL, DR),\n        ][value - 1]\n\n        arrangement = VGroup(*(\n            dot.copy().move_to(square.get_bounding_box_point(vect))\n            for vect in edge_group\n        ))\n        arrangement.space_out_submobjects(dot_coalesce_factor)\n\n        super().__init__(square, arrangement)\n        self.dots = arrangement","sourceCodeStart":693,"sourceCodeEnd":729,"githubUrl":"https://github.com/3b1b/manim/blob/dee01804d47b9f94402d71472674710dcac125b8/manimlib/mobject/svg/drawings.py#L693-L729","documentation":"Raised by DieFace.__init__ (drawings.py:711) when the value argument falls outside 1..6. The class indexes a fixed six-entry pip-arrangement table with value - 1, so any other integer (or non-integer) is rejected before indexing.","triggerScenarios":"DieFace(0), DieFace(7), or DieFace(value) with a value from random.randint(1, 8) / user input that escaped the range; also non-integers like DieFace(3.5) fail the comparison chain (1 <= 3.5 <= 6 is True, but then value - 1 = 2.5 breaks list indexing with a TypeError instead).","commonSituations":"Simulating dice with randrange bounds off by one (randrange(7) yields 0..6); passing a configurable 'number of pips' that can exceed six; using DieFace to render generic counters.","solutions":["Clamp or re-map the value into 1..6 before constructing: value = min(max(value, 1), 6)","Fix random generation: random.randint(1, 6), not randrange(7) or randint(1, 8)","For counts above six, use a different mobject (e.g. a Square with a Tex label) instead of DieFace"],"exampleFix":"# before\nface = DieFace(random.randrange(7))  # can be 0 -> raises\n\n# after\nface = DieFace(random.randint(1, 6))","handlingStrategy":"validation","validationCode":"value = int(value)\nif not 1 <= value <= 6:\n    raise ValueError(f'DieFace value must be 1..6, got {value}')\nface = DieFace(value)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use random.randint(1, 6) — not randrange(7) or randint(1, 8)","Clamp external inputs to 1..6 before constructing DieFace","For pip counts above six, use a Square with a Tex label instead"],"tags":["manim","dieface","range-check","drawings"],"backgroundTag":null,"analyzedSha":"dee01804d47b9f94402d71472674710dcac125b8","analyzedAt":"2026-08-14T19:53:44.241Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}