{"record":{"id":"1884e59f14527ffb","repo":"kovidgoyal/kitty","slug":"warning-unable-to-parse-dircolors-line-line","errorCode":null,"errorMessage":"Warning: unable to parse dircolors line \"{line}\"","messagePattern":"Warning: unable to parse dircolors line \"(.+?)\"","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"warning","filePath":"kittens/tui/dircolors.py","lineNumber":304,"sourceCode":"                self.codes[code] = color\n\n        return bool(self.codes or self.extensions)\n\n    def load_from_environ(self, envvar: str = 'LS_COLORS') -> bool:\n        return self.load_from_lscolors(os.environ.get(envvar) or '')\n\n    def load_from_dircolors(self, database: str, strict: bool = False) -> bool:\n        self.clear()\n\n        for line in database.splitlines():\n            line = line.split('#')[0].strip()\n            if not line:\n                continue\n\n            split = line.split()\n            if len(split) != 2:\n                if strict:\n                    raise ValueError(f'Warning: unable to parse dircolors line \"{line}\"')\n                continue\n\n            key, val = split\n            if key == 'TERM':\n                continue\n            if key in CODE_MAP:\n                self.codes[CODE_MAP[key]] = val\n            elif key.startswith('.'):\n                self.extensions[key] = val\n            elif strict:\n                raise ValueError(f'Warning: unable to parse dircolors line \"{line}\"')\n\n        return bool(self.codes or self.extensions)\n\n    def load_defaults(self) -> bool:\n        self.clear()\n        return self.load_from_dircolors(DEFAULT_DIRCOLORS, True)\n","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/tui/dircolors.py#L286-L322","documentation":"Raised by load_from_dircolors() in strict mode when a line in a dircolors file does not split into exactly two whitespace-separated tokens (key and value). The dircolors parser only understands simple 'key value' pairs; comments, blank lines and multi-token directives are not supported outside its limited handling. It is a warning-message text wrapped in a ValueError, mirroring what the dircolors(1) utility would print.","triggerScenarios":"Calling load_from_file() or load_defaults() (which calls load_from_dircolors with strict=True) on a dircolors file containing lines with more or fewer than 2 tokens, e.g. 'CONSOLE 01 32' semantics, trailing annotations, or a malformed/custom dircolors file.","commonSituations":"User has a custom ~/.dircolors/LS_COLORS file from another tool (e.g. vivid, dircolors -p output edited by hand) with unsupported syntax; system-wide /etc/DIR_COLORS containing legacy multi-token lines; stray whitespace or embedded spaces in values.","solutions":["Fix or remove the offending line in the dircolors file so it is exactly 'KEY value'","Generate the file with dircolors -p and edit only supported keys","Call load_from_dircolors(data, strict=False) to skip unparseable lines instead of raising"],"exampleFix":"# before\nresult = d.load_from_file('/home/user/.dircolors')  # raises on bad line\n# after\nresult = d.load_from_dircolors(open('/home/user/.dircolors').read(), False)  # skips bad lines","handlingStrategy":"validation","validationCode":"def parseable_dircolors(data: str) -> list[str]:\n    bad = []\n    for line in data.splitlines():\n        if not line or line.startswith('#'):\n            continue\n        if len(line.split()) != 2:\n            bad.append(line)\n    return bad","typeGuard":null,"tryCatchPattern":"try:\n    ok = d.load_from_file(path)\nexcept ValueError as e:\n    if 'unable to parse dircolors line' in str(e):\n        log.warning('skipping bad dircolors line: %s', e)\n    else:\n        raise","preventionTips":["Pre-validate dircolors files before loading","Use strict=False for user-supplied files","Keep custom dircolors files to simple 'KEY value' pairs"],"tags":["dircolors","config-parsing","kitty","ls-colors"],"backgroundTag":"config-file-parse-error","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}