can1357/oh-my-pi · error · HTTPException

remote url has invalid port

Error message

remote url has invalid port

What it means

Raised when urlparse(url).port throws ValueError because the origin URL contains a malformed port (e.g. https://github.com:notaport/...). The proxy treats this as an invalid URL and refuses the operation with 400 rather than passing a corrupt URL to git.

Source

Thrown at python/robomp/src/proxy/server.py:324

        log.warning(
            "gh-proxy: refusing git op — origin has ambiguous remote urls",
            extra={"expected_repo": expected_repo, "kind": kind, "count": len(urls)},
        )
        raise HTTPException(400, f"origin must have exactly one {kind} url")
    return urls[0]


def _normalized_github_https_url(url: str, expected_repo: str) -> str:
    _validate_repo_name(expected_repo)
    parsed = urlparse(url)
    if (parsed.scheme or "").lower() != "https":
        raise HTTPException(400, f"remote url must be https://github.com/{expected_repo}[.git]")
    if parsed.username or parsed.password:
        raise HTTPException(400, "remote url must not contain embedded credentials")
    try:
        port = parsed.port
    except ValueError as exc:
        raise HTTPException(400, "remote url has invalid port") from exc
    if port is not None:
        raise HTTPException(400, "remote url must not specify a port")
    if (parsed.hostname or "").lower() != "github.com":
        raise HTTPException(400, f"remote url host must be github.com for repo {expected_repo!r}")
    if parsed.params or parsed.query or parsed.fragment:
        raise HTTPException(400, "remote url must not contain params, query, or fragment")
    path = parsed.path.strip("/")
    if path.endswith(".git"):
        path = path[:-4]
    if path.lower() != expected_repo.lower():
        raise HTTPException(400, f"remote url does not match repo {expected_repo!r}")
    return _github_url_for_repo(expected_repo)


def _remote_auth_for_url(url: str, expected_repo: str, token: str) -> _RemoteAuth:
    raw = url.strip()
    if not raw or raw != url:
        raise HTTPException(400, "remote url must not be empty or padded")

View on GitHub (pinned to 9690622007)

Solutions

  1. Fix the URL: `git remote set-url origin https://github.com/<owner>/<repo>.git`
  2. Verify with `git config --get remote.origin.url` and compare against the expected https URL
  3. Avoid manual edits to .git/config; use `git remote set-url`

Example fix

// before (mangled separator)
url = "https:github.com:abc/acme/repo.git"
// after
url = "https://github.com/acme/repo.git"
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse

def origin_url_parses(url: str) -> bool:
    try:
        urlparse(url).port
        return True
    except ValueError:
        return False

Try / catch

from fastapi import HTTPException

try:
    result = client.post("/git/op", json={"repo": "acme/repo"})
except HTTPException as e:
    if e.status_code == 400 and "invalid port" in e.detail:
        reset_origin(worktree_dir, "acme/repo")  # rewrite mangled URL
    else:
        raise

Prevention

When it happens

Trigger: Origin URL like https://github.com:abc/acme/repo.git where text after ':' is not a valid integer port — a typo (colon instead of slash) or a corrupted remote URL.

Common situations: Hand-edited .git/config URLs; sed/regex rewrites of remote URLs that mangled the scheme separator; copy-paste errors like https:/github.com or https://github.com:443x/...

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/b918c49e334bdbc1. Report an issue: GitHub.