jackwener/OpenCLI · error · ArgumentError

goproxy module path "${value}" is not a recognised Go module

Error message

goproxy module path "${value}" is not a recognised Go module path

What it means

Thrown by requireModulePath when the value is non-empty but fails either the MODULE_PATH regex (/^[A-Za-z0-9][A-Za-z0-9._\/-]{0,199}$/) or the must-contain-at-least-one-slash check at clis/goproxy/utils.js:27. The library enforces a conservative Go module path shape to avoid building malformed proxy.golang.org URLs.

Source

Thrown at clis/goproxy/utils.js:28

// Module paths look like host/path/...; conservative shape: at least one slash,
// host segment is alnum + dots, path segments are alnum + dashes/dots/underscores/slashes.
// We enforce at most 200 chars and reject characters that would need URL-escaping.
const MODULE_PATH = /^[A-Za-z0-9][A-Za-z0-9._\/-]{0,199}$/;

// Go semver tags include "v" prefix; we accept the GOPROXY canonical form.
const VERSION_TAG = /^v[0-9]+(\.[0-9]+)*([-+][A-Za-z0-9._-]+)?$/;

export function requireModulePath(value) {
    const s = String(value ?? '').trim();
    if (!s) {
        throw new ArgumentError(
            'goproxy module path is required (e.g. "github.com/gin-gonic/gin", "golang.org/x/net")',
            'Use the canonical module path that appears in `go.mod`.',
        );
    }
    if (!MODULE_PATH.test(s) || !s.includes('/')) {
        throw new ArgumentError(
            `goproxy module path "${value}" is not a recognised Go module path`,
            'Module paths look like "github.com/<org>/<repo>" or "golang.org/x/<name>".',
        );
    }
    return s;
}

export function requireVersionTag(value) {
    const s = String(value ?? '').trim();
    if (!s) throw new ArgumentError('goproxy --version cannot be empty');
    if (!VERSION_TAG.test(s)) {
        throw new ArgumentError(
            `goproxy --version "${value}" is not a valid Go semver tag`,
            'Use the GOPROXY canonical form like "v1.2.3" or "v0.0.0-20240101010101-abcdef012345".',
        );
    }
    return s;
}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use the full host-qualified path from go.mod, e.g. 'github.com/gin-gonic/gin' or 'golang.org/x/net' — not a repo URL or short name.
  2. Strip scheme/'www.' prefixes: 'https://github.com/org/repo' → 'github.com/org/repo'.
  3. Check for stray characters (spaces, quotes) and length ≤ 200; the value must start with an alphanumeric character and contain at least one '/'.
  4. Run `go list -m` in the project to get the exact canonical module path.

Example fix

// before
modulePath('https://github.com/gin-gonic/gin');
// after
modulePath('github.com/gin-gonic/gin');
Defensive patterns

Strategy: validation

Validate before calling

const MODULE_PATH = /^[A-Za-z0-9][A-Za-z0-9._\/-]{0,199}$/;
function validateModulePath(v) {
  const s = String(v ?? '').trim();
  if (!MODULE_PATH.test(s) || !s.includes('/')) throw new Error(`not a Go module path: ${s}`);
  return s;
}
validateModulePath(input);

Type guard

const looksLikeGoModule = (v) =>
  typeof v === 'string' && v.includes('/') && /^[A-Za-z0-9][A-Za-z0-9._\/-]{0,199}$/.test(v);

Try / catch

try {
  const mod = modulePath(raw);
} catch (err) {
  if (err instanceof ArgumentError) {
    console.error(`'${raw}' is not a Go module path — use host/org/repo form from go.mod`);
    process.exitCode = 2;
  } else throw err;
}

Prevention

When it happens

Trigger: Passing values like 'gin', 'github.com' (no slash), 'my module' (space), a URL 'https://github.com/gin-gonic/gin', a path over 200 chars, or one starting with '/', '.', or '-'.

Common situations: Users pasting a browser URL instead of the module path; omitting the host segment ('gin-gonic/gin'); single-segment standard-library names like 'fmt'; shell quoting leaving stray characters or whitespace.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/e6aefcbbf5c0d01a. Report an issue: GitHub.