{"record":{"id":"7f70edc8bfdcb663","repo":"affaan-m/ECC","slug":"remote-import-url-is-missing-a-hostname","errorCode":null,"errorMessage":"remote import URL is missing a hostname","messagePattern":"remote import URL is missing a hostname","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"skills/continuous-learning-v2/scripts/instinct-cli.py","lineNumber":195,"sourceCode":"    \"\"\"Validate instinct IDs before using them in filenames.\"\"\"\n    if not instinct_id or len(instinct_id) > 128:\n        return False\n    if \"/\" in instinct_id or \"\\\\\" in instinct_id:\n        return False\n    if \"..\" in instinct_id:\n        return False\n    if instinct_id.startswith(\".\"):\n        return False\n    return bool(re.match(r\"^[A-Za-z0-9][A-Za-z0-9._-]*$\", instinct_id))\n\n\ndef _validate_import_url(source: str) -> str:\n    \"\"\"Validate remote instinct imports before opening a network connection.\"\"\"\n    parsed = urllib.parse.urlparse(source)\n    if parsed.scheme != \"https\":\n        raise ValueError(\"remote instinct imports require https URLs\")\n    if not parsed.hostname:\n        raise ValueError(\"remote import URL is missing a hostname\")\n\n    try:\n        addr_infos = socket.getaddrinfo(parsed.hostname, parsed.port or 443, type=socket.SOCK_STREAM)\n    except socket.gaierror as exc:\n        raise ValueError(f\"remote import host could not be resolved: {parsed.hostname}\") from exc\n\n    for family, _, _, _, sockaddr in addr_infos:\n        host = sockaddr[0]\n        try:\n            ip = ipaddress.ip_address(host)\n        except ValueError:\n            continue\n        if (\n            ip.is_private\n            or ip.is_loopback\n            or ip.is_link_local\n            or ip.is_multicast\n            or ip.is_reserved","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/affaan-m/ECC/blob/8321021c54d670126ce3b2969d5deb880b4b0c2a/skills/continuous-learning-v2/scripts/instinct-cli.py#L177-L213","documentation":"Raised by _validate_import_url when urlparse produces an empty/absent hostname for the import source. Without a hostname the CLI cannot resolve or reach any server, so the URL is rejected before network access. Typically indicates a malformed or scheme-relative URL.","triggerScenarios":"Passing sources like 'https://' (no host), '//example.com/file', 'file:///etc/passwd', or plain paths/strings that urlparse cannot interpret as host-bearing URLs.","commonSituations":"String concatenation bugs that drop the host portion; config templates with unfilled placeholders (https://{{HOST}}/x); users passing a local file path to a command that expects a URL.","solutions":["Supply a complete URL including the host: https://example.com/path.","Validate before calling: bool(urllib.parse.urlparse(source).hostname).","Fix template/config values that left the host empty.","If importing local content, use the local import path/flag instead of the remote URL flag."],"exampleFix":"# before\nsource = base_url + \"/instincts.yaml\"  # base_url was \"\"\n# after\nbase_url = base_url or \"https://instincts.example.com\"\nsource = f\"{base_url}/instincts.yaml\"\nassert urllib.parse.urlparse(source).hostname","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\nif not urlparse(source).hostname:\n    raise ValueError(f\"URL missing hostname: {source}\")","typeGuard":null,"tryCatchPattern":"try:\n    cli_import(url=source)\nexcept ValueError as e:\n    if \"missing a hostname\" in str(e):\n        print(f\"malformed URL: {source}\")","preventionTips":["Build URLs with f-strings/templates that fail loudly on empty base hosts","Validate parsed hostname before calling the CLI","Don't pass local file paths where a URL is expected","Check config placeholders ({{HOST}}) are filled"],"tags":["python","url-validation","network","cli"],"backgroundTag":"invalid-url-format","analyzedSha":"8321021c54d670126ce3b2969d5deb880b4b0c2a","analyzedAt":"2026-09-16T10:08:13.343Z","contentChangedAt":"2026-09-16T10:08:13.343Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}