{"record":{"id":"4d97830449868e39","repo":"iflytek/astron-agent","slug":"bad-port","errorCode":null,"errorMessage":"Bad Port!! ","messagePattern":"Bad Port!! ","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"core/workflow/extensions/otlp/sid/sid_generator2.py","lineNumber":75,"sourceCode":"        # Initialize sequential index counter\n        self.index = 0\n\n        # Parse and validate IP address\n        ip = socket.inet_aton(localIp)\n        if ip:\n            # Extract the last two octets of the IP address\n            ipSec3 = ip[2]\n            ipSec4 = ip[3]\n            ip3 = ipSec3 & 0xFF\n            ip4 = ipSec4 & 0xFF\n            # Create short IP representation using last two octets\n            self.ShortLocalIP = f\"{ip3:02x}{ip4:02x}\"\n        else:\n            raise ValueError(\"Bad IP !! \" + localIp)\n\n        # Validate port number length\n        if len(localPort) < 4:\n            raise ValueError(\"Bad Port!! \")\n\n        # Store configuration parameters\n        self.port = localPort\n        self.location = location\n        self.sub = sub\n        logger.debug(\"✅ SID generator initialized successfully\")\n\n    def gen(self) -> str:\n        \"\"\"\n        Generate a unique session identifier.\n\n        The SID format is: {sub}{pid}{index}@{location}{timestamp}{ip}{port}{version}\n\n        :return: A unique session identifier string\n        \"\"\"\n        # Use default subject if empty\n        if len(self.sub) == 0:\n            self.sub = \"src\"","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/core/workflow/extensions/otlp/sid/sid_generator2.py#L57-L93","documentation":"SidGenerator2.__init__ requires the localPort string to be at least 4 characters long because the port is embedded in the generated SID. If a shorter string (empty, 1–3 chars) is passed it raises ValueError(\"Bad Port!! \"). This is a length/format validation on the constructor argument, not a range check on the numeric port.","triggerScenarios":"Constructing SidGenerator2(sub, location, localIp, localPort) with localPort as '', '80', '999', or a non-padded short string — e.g. an unset env var defaulting to '' or a port passed as int-ish short string.","commonSituations":"PORT env var missing in local development; passing str(int_port) for ports below 1000; config templates leaving the port blank.","solutions":["Pass the port as a string of at least 4 characters (e.g. '9100'); for short ports zero-pad, e.g. str(port).zfill(4) or '0' + port.","Ensure the PORT env var is set before service startup and defaults sensibly.","Pre-validate with len(localPort) >= 4 before constructing the generator.","Pass a str, not an int — an int would also fail on len()."],"exampleFix":"// before\ngen = SidGenerator2(sub, loc, ip, str(808))\n// after\nport_str = str(808).zfill(4)  # '0808'\ngen = SidGenerator2(sub, loc, ip, port_str)","handlingStrategy":"validation","validationCode":"def valid_port_str(p):\n    return isinstance(p, str) and len(p) >= 4\nport_str = str(port).zfill(4)\nassert valid_port_str(port_str), f\"invalid localPort: {port_str!r}\"","typeGuard":"def is_valid_port(p):\n    return isinstance(p, str) and len(p) >= 4 and p.isdigit()","tryCatchPattern":"try:\n    gen = SidGenerator2(sub, location, local_ip, port_str)\nexcept ValueError as e:\n    logger.error(f\"sid generator port invalid: {e}\")\n    raise","preventionTips":["Zero-pad ports below 1000 before passing them in (str(port).zfill(4)).","Always pass the port as a str, never an int.","Set the PORT env var explicitly in every deployment, including local dev."],"tags":["validation","configuration","port","observability"],"backgroundTag":"invalid-argument-format","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}