{"record":{"id":"8b4421bfcb7d61bd","repo":"XX-net/XX-Net","slug":"load-config-s-except-r","errorCode":null,"errorMessage":"load config %s except:%r","messagePattern":"load config (.+?) except:%r","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"code/default/launcher/win_compat_suggest.py","lineNumber":71,"sourceCode":"            out = proc.stdout\n            lines = out.readlines()\n            return lines\n        except Exception as e:\n            xlog.warn(\"Win10PortReserveSolution run cmd %s error:%r\", cmd, e)\n            return []\n\n    @staticmethod\n    def get_config_value(fn, key, default_value):\n        if not os.path.isfile(fn):\n            return default_value\n\n        try:\n            with open(fn, \"r\") as fd:\n                dat = json.load(fd)\n                value = dat.get(key, default_value)\n                return value\n        except Exception as e:\n            xlog.warn(\"load config %s except:%r\", fn, e)\n            return default_value\n\n    def get_service_ports(self):\n        web_console_port = config.control_port\n        smart_router_config_fn = os.path.join(data_path, \"smart_router\", \"config.json\")\n        smart_router_socks_port = self.get_config_value(smart_router_config_fn, \"proxy_port\", 8086)\n        smart_router_dns_port = self.get_config_value(smart_router_config_fn, \"dns_backup_port\", 8053)\n\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\" \"):","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/XX-net/XX-Net/blob/cfa5bc17b67676e467f37ec50766127e0ab5f0aa/code/default/launcher/win_compat_suggest.py#L53-L89","documentation":"get_config_value() tries to json.load a service config file (e.g. data/smart_router/config.json) and read a key; on any error it logs this warning and returns default_value — a soft fallback, not a crash.","triggerScenarios":"The JSON file is missing, empty, unreadable, or malformed; get_service_ports then falls back to defaults like 8086.","commonSituations":"First run before smart_router wrote its config; config corrupted by a crash mid-write; permission problems on the data dir.","solutions":["Check the printed file path exists and is valid JSON (python -m json.tool).","Delete/recreate the file and let the service regenerate it.","Fix permissions on the data directory.","Accept the default value if the service hasn't initialized yet."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import json, os\ndef read_conf(fn, key, default):\n    try:\n        with open(fn) as f: return json.load(f).get(key, default)\n    except Exception: return default","typeGuard":null,"tryCatchPattern":"try:\n    value = json.load(open(fn)).get(key, default)\nexcept (OSError, ValueError):\n    value = default  # file missing or corrupt; service will regenerate","preventionTips":["Treat returned defaults as 'config not ready'.","Don't hand-edit service JSON while the service is writing.","Regenerate corrupt configs by deleting them."],"tags":["json","config","filesystem","fallback"],"backgroundTag":"config-json-parse-failed","analyzedSha":"cfa5bc17b67676e467f37ec50766127e0ab5f0aa","analyzedAt":"2026-08-27T19:28:28.225Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}