{"record":{"id":"8892b713576a948d","repo":"XX-net/XX-Net","slug":"parse-reserve-port-fail-line-s-e-r","errorCode":null,"errorMessage":"parse reserve port fail, line:%s, e:%r","messagePattern":"parse reserve port fail, line:(.+?), e:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/launcher/win_compat_suggest.py","lineNumber":97,"sourceCode":"\n        x_tunnel_config_fn = os.path.join(data_path, \"x_tunnel\", \"client.json\")\n        x_tunnel_port = self.get_config_value(x_tunnel_config_fn, \"socks_port\", 1080)\n\n        return [web_console_port, smart_router_socks_port, smart_router_dns_port, x_tunnel_port]\n\n    def is_port_reserve_conflict(self):\n        cmd = \"netsh int ipv4 show excludedportrange protocol=tcp\"\n        lines = self.run_cmd(cmd)\n        for line in lines:\n            if not line.startswith(b\" \"):\n                continue\n\n            range_str = line.split()\n            try:\n                p0 = int(range_str[0])\n                p1 = int(range_str[1])\n            except Exception as e:\n                xlog.warn(\"parse reserve port fail, line:%s, e:%r\", line, e)\n                continue\n\n            # xlog.debug(\"range:%d - %d\", p0, p1)\n            for port in self.service_ports:\n                if p0 < port < p1:\n                    xlog.info(\"found port reserved range:%d - %d, expect %d\", p0, p1, port)\n                    return True\n\n        return False\n\n    def search_port_range(self):\n        port_number = 16384\n        for port_start in range(10000, 45000, 5000):\n            port_end = port_start + port_number\n            acceptable = True\n            for port in self.service_ports:\n                if port_start <= port <= port_end:\n                    acceptable = False","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/launcher/win_compat_suggest.py#L79-L115","documentation":"While scanning the Windows excluded port ranges (output of 'netsh int ipv4 show excludedportrange protocol=tcp'), the launcher could not parse a line into two integers (start/end of a range). This is a warning-level diagnostic: the unparseable line is skipped with 'continue' and scanning proceeds, so it never aborts the port-conflict check.","triggerScenarios":"Calling is_port_reserve_conflict() (directly or via check_and_resolve) on Windows when netsh output contains a header line, blank line, or localized/unexpected formatting, so line.split() yields fewer than 2 tokens or non-numeric tokens, making int(range_str[0])/int(range_str[1]) raise ValueError/IndexError.","commonSituations":"Non-English Windows where netsh prints localized headers; netsh output format differences across Windows 10/11 or Server editions; trailing blank lines in command output; systems where Hyper-V/WSL adds unusual range rows.","solutions":["Check the logged raw line to see whether it is just a header/blank line (harmless — ignore the warning).","Run 'netsh int ipv4 show excludedportrange protocol=tcp' manually and compare its layout with the parser's expectations.","If output is localized, force English output or make the parser skip lines that don't match a digits-only pattern before int().","Update win_compat_suggest.py to filter lines with a regex like r'^\\s*\\d+\\s+\\d+' before parsing."],"exampleFix":"// before\nrange_str = line.split()\ntry:\n    p0 = int(range_str[0])\n    p1 = int(range_str[1])\nexcept Exception as e:\n    xlog.warn(\"parse reserve port fail, line:%s, e:%r\", line, e)\n    continue\n\n// after\nimport re\nm = re.match(r'^\\s*(\\d+)\\s+(\\d+)', line)\nif not m:\n    xlog.debug(\"skip non-range line:%r\", line)\n    continue\np0, p1 = int(m.group(1)), int(m.group(2))","handlingStrategy":"validation","validationCode":"import re\ndef is_port_range_line(line):\n    return bool(re.match(r'^\\s*\\d+\\s+\\d+\\s*$', line))\n\n# before parsing each netsh output line:\nif not is_port_range_line(line):\n    continue","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Filter netsh output lines with a digits-pair regex before int() conversion.","Strip headers and blank lines from command output before parsing.","Never assume locale-fixed command output on Windows; match structure, not position."],"tags":["windows","netsh","port-reservation","parsing","launcher"],"backgroundTag":"command-output-parse-failure","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}