{"record":{"id":"f5c91586f7788d8b","repo":"kitao/pyxel","slug":"width-or-height-must-be-specified-but-not-both","errorCode":null,"errorMessage":"width or height must be specified, but not both","messagePattern":"width or height must be specified, but not both","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pyxel/editor/widgets/scroll_bar.py","lineNumber":31,"sourceCode":"    # Events:\n    #   change (value)\n\n    def __init__(\n        self,\n        parent,\n        x,\n        y,\n        *,\n        width=None,\n        height=None,\n        scroll_amount,\n        slider_amount,\n        value,\n        with_shadow=True,\n        **kwargs,\n    ):\n        if (width is None) == (height is None):\n            raise ValueError(\"width or height must be specified, but not both\")\n\n        if height is not None:\n            width = 7\n            self._is_vertical = True\n        else:\n            height = 7\n            self._is_vertical = False\n\n        super().__init__(parent, x, y, width, height, **kwargs)\n        self.scroll_amount = scroll_amount\n        self.slider_amount = slider_amount\n        self._with_shadow = with_shadow\n        self._drag_offset = 0\n        self._is_dragged = False\n\n        self.new_var(\"value_var\", value)\n        self.add_var_event_listener(\"value_var\", \"set\", self.__on_value_set)\n        self.add_var_event_listener(\"value_var\", \"change\", self.__on_value_change)","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/kitao/pyxel/blob/50f9bd77780c993aca62b5b221766bde5791081d/python/pyxel/editor/widgets/scroll_bar.py#L13-L49","documentation":"Pyxel's ScrollBar widget requires exactly one of `width` or `height`: width implies a horizontal scroll bar, height a vertical one (the other dimension is hardcoded to 7). Passing neither, or both, is ambiguous, so the constructor raises ValueError immediately.","triggerScenarios":"Calling ScrollBar(...) with width=None and height=None, or with both width and height set. Any keyword misuse like ScrollBar(width=10, height=10) or omitting both dimensions in the editor widget config.","commonSituations":"Building a custom editor layout and copying constructor args between horizontal and vertical bars without removing the other dimension; dynamically computing width/height where both may end up non-None; forgetting to pass a dimension when the widget is created from kwargs.","solutions":["Pass exactly one dimension: `width=N` for a horizontal bar, `height=N` for a vertical bar.","If computing dimensions dynamically, ensure only one is ever set (e.g. pass the other as None explicitly).","If a scrollbar direction is configurable, branch before construction and build kwargs with only the relevant dimension."],"exampleFix":"// before\nbar = ScrollBar(x=0, y=0, width=100, height=100, slider_amount=10, value=0)\n// after\nbar = ScrollBar(x=0, y=0, width=100, height=None, slider_amount=10, value=0)  # horizontal","handlingStrategy":"validation","validationCode":"def make_scrollbar(x, y, width=None, height=None, **kwargs):\n    if (width is None) == (height is None):\n        raise ValueError(\"specify exactly one of width (horizontal) or height (vertical)\")\n    return ScrollBar(x=x, y=y, width=width, height=height, **kwargs)","typeGuard":"def scrollbar_dims_ok(width, height):\n    return (width is None) != (height is None)","tryCatchPattern":null,"preventionTips":["Always pass exactly one of width/height; set the other to None explicitly.","Document scrollbar orientation at call sites so the dimension choice is obvious.","Write a small factory helper that builds horizontal/vertical bars with fixed signatures."],"tags":["python","widget","argument-validation"],"backgroundTag":"mutually-exclusive-arguments","analyzedSha":"50f9bd77780c993aca62b5b221766bde5791081d","analyzedAt":"2026-09-03T10:27:43.285Z","contentChangedAt":"2026-09-03T10:27:43.285Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}