iflytek/astron-agent · error · ValueError
Bad Port!!
Error message
Bad Port!!
What it means
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.
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().
Example fix
// before gen = SidGenerator2(sub, loc, ip, str(808)) // after port_str = str(808).zfill(4) # '0808' gen = SidGenerator2(sub, loc, ip, port_str)
Defensive patterns
Strategy: validation
Validate before calling
def valid_port_str(p):
return isinstance(p, str) and len(p) >= 4
port_str = str(port).zfill(4)
assert valid_port_str(port_str), f"invalid localPort: {port_str!r}" Type guard
def is_valid_port(p):
return isinstance(p, str) and len(p) >= 4 and p.isdigit() Try / catch
try:
gen = SidGenerator2(sub, location, local_ip, port_str)
except ValueError as e:
logger.error(f"sid generator port invalid: {e}")
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: PORT env var missing in local development; passing str(int_port) for ports below 1000; config templates leaving the port blank.
Understand the failure class
Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.
Related errors
- Bad IP !!
- ENG_PROTOCOL_VALIDATE_ERROR
- FILE_INVALID_ERROR
- must contain only ASCII letters, digits, '.', '_', '~', or
- size limit is invalid
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/4d97830449868e39.
Report an issue: GitHub.
Appendix: source
Thrown at core/workflow/extensions/otlp/sid/sid_generator2.py:75
# Initialize sequential index counter
self.index = 0
# Parse and validate IP address
ip = socket.inet_aton(localIp)
if ip:
# Extract the last two octets of the IP address
ipSec3 = ip[2]
ipSec4 = ip[3]
ip3 = ipSec3 & 0xFF
ip4 = ipSec4 & 0xFF
# Create short IP representation using last two octets
self.ShortLocalIP = f"{ip3:02x}{ip4:02x}"
else:
raise ValueError("Bad IP !! " + localIp)
# Validate port number length
if len(localPort) < 4:
raise ValueError("Bad Port!! ")
# Store configuration parameters
self.port = localPort
self.location = location
self.sub = sub
logger.debug("✅ SID generator initialized successfully")
def gen(self) -> str:
"""
Generate a unique session identifier.
The SID format is: {sub}{pid}{index}@{location}{timestamp}{ip}{port}{version}
:return: A unique session identifier string
"""
# Use default subject if empty
if len(self.sub) == 0:
self.sub = "src"View on GitHub (pinned to 5e758547a8)