{"record":{"id":"ede30864f2fc7db8","repo":"deepfakes/faceswap","slug":"hex-color-codes-should-start-with-a-and-be-6-c","errorCode":null,"errorMessage":"Hex color codes should start with a '#' and be 6 characters long. Got: '{value}'","messagePattern":"Hex color codes should start with a '#' and be 6 characters long\\. Got: '(.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"lib/config/objects.py","lineNumber":400,"sourceCode":"\n        if self.datatype is list:\n            if not isinstance(value, (str, list)):\n                raise ValueError(f\"[{self._name}] List values should be set as a Str or List. Got \"\n                                 f\"{type(value)} ({value})\")\n            value = cast(T, self._parse_list(value))\n\n        if not isinstance(value, self.datatype):\n            raise ValueError(\n                f\"[{self._name}] Expected {self.datatype} got {type(value)} ({value})\")\n\n        if isinstance(self.choices, list) and self.choices:\n            assert isinstance(value, (list, str))\n            value = cast(T, self._validate_selection(value))\n\n        if self.choices == \"colorchooser\":\n            assert isinstance(value, str)\n            if not value.startswith(\"#\") or len(value) != 7:\n                raise ValueError(f\"Hex color codes should start with a '#' and be 6 \"\n                                 f\"characters long. Got: '{value}'\")\n\n        self._value = value\n\n    def set_name(self, name: str) -> None:\n        \"\"\"Set the logging name for this object for display purposes\n\n        Parameters\n        ----------\n        name\n            The name to assign to this option\n        \"\"\"\n        logger.debug(\"Setting name to '%s'\", name)\n        assert isinstance(name, str) and name\n        self._name = name\n\n    def __call__(self) -> T:\n        \"\"\"Obtain the currently stored configuration value","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/deepfakes/faceswap/blob/f530cb7508ae670f6474f8a7d9c4df94705cf96b/lib/config/objects.py#L382-L418","documentation":"Apple Silicon GPU stats plugin (lib/gpu_stats/apple_silicon.py) sanity-checks the Torch MPS backend by calling torch.mps.driver_allocated_memory(). If that call raises RuntimeError, Faceswap wraps it as FaceswapError, since a broken MPS stack means no usable Apple GPU.","triggerScenarios":"Selecting apple Silicon GPU stats (e.g. `faceswap.py --apple-silicon` or auto-detection on an M-series Mac) with a torch build lacking MPS support, a too-old macOS/torch version, or a corrupted Metal/torch install; also when torch imports but the MPS device is unavailable.","commonSituations":"Upgrading/downgrading torch or macOS and breaking MPS; conda envs shipping CPU-only torch on ARM; running under Rosetta where MPS is unavailable; beta macOS with incompatible Metal drivers.","solutions":["Verify MPS outside Faceswap: `python -c \"import torch; print(torch.backends.mps.is_available()); print(torch.mps.driver_allocated_memory())\"` and read the original error","Reinstall a torch build matching your macOS/arch (e.g. pip install --force-reinstall torch on native arm64, no Rosetta)","Update macOS/Xcode command line tools so Metal drivers match the torch build; as a fallback run with CPU (`--cpu`) while the GPU stack is repaired"],"exampleFix":"# before\npython faceswap.py --apple-silicon train ...  # -> FaceswapError wrapping torch.mps RuntimeError\n\n# after\n# 1) verify the stack\npython -c \"import torch; print(torch.backends.mps.is_available())\"\n# 2) reinstall matching torch, then retry\npip uninstall -y torch && pip install torch\n# 3) meanwhile run CPU-only\npython faceswap.py --cpu train ...","handlingStrategy":"validation","validationCode":"import re\n\ndef valid_hex_color(v: str) -> bool:\n    return bool(re.fullmatch(r\"#[0-9a-fA-F]{6}\", v))\n\nassert valid_hex_color(option_value), f\"bad color: {option_value!r}\"","typeGuard":"import re\n\ndef is_hex_color(v) -> bool:\n    \"\"\"True when v is a '#rrggbb' string accepted by colorchooser options.\"\"\"\n    return isinstance(v, str) and bool(re.fullmatch(r\"#[0-9a-fA-F]{6}\", v))","tryCatchPattern":"try:\n    option.set(color)\nexcept ValueError:\n    r, g, b = tuple(int(color.lstrip(\"#\")[i:i+2], 16) for i in (0, 2, 4))\n    option.set(\"#%02x%02x%02x\" % (r, g, b))","preventionTips":["Normalize all colors to '#rrggbb' at config load time","Use a shared to_hex(r,g,b) helper instead of string concatenation","Reject 3/4/8-digit hex at the UI boundary"],"tags":["faceswap","apple-silicon","mps","torch","gpu","environment"],"backgroundTag":null,"analyzedSha":"f530cb7508ae670f6474f8a7d9c4df94705cf96b","analyzedAt":"2026-08-15T02:59:26.626Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}