Hmbown/CodeWhale · error · Error

invalid --base-url

Error message

invalid --base-url: ${args.baseUrl}

What it means

main() validates the --base-url value by constructing a URL object; if parsing fails it throws with the offending value. This guard runs before any network request so a malformed or missing URL fails immediately with a clear message.

Solutions

  1. Pass a full absolute URL including scheme: --base-url https://deploy.example.com
  2. Quote the URL in the shell so special characters survive: --base-url "https://example.com/path".
  3. Verify the flag is actually set (a missing flag yields `invalid --base-url: undefined`).
  4. Note: the URL must parse AND use http/https — a valid but non-http(s) URL fails the next check.

Example fix

// before
node compare-deployed-facts.mjs --base-url localhost:8080
// after
node compare-deployed-facts.mjs --base-url http://localhost:8080
Defensive patterns

Strategy: validation

Validate before calling

let u; try { u = new URL(args.baseUrl); } catch { throw new Error("--base-url must be an absolute http(s) URL"); } if (!/^https?:$/.test(u.protocol)) throw new Error("--base-url must use http or https");

Type guard

const isHttpUrl = (s) => { try { return /^https?:$/.test(new URL(s).protocol); } catch { return false; } };

Try / catch

try { main(); } catch (e) { if (e.message.startsWith("invalid --base-url")) console.error("Pass an absolute URL, e.g. --base-url https://deploy.example.com"); }

Prevention

When it happens

Trigger: Running the script without --base-url (undefined), or with a value that is not an absolute URL — e.g. `localhost:8080` without scheme, `deploy.example.com`, or a value containing unescaped spaces.

Common situations: Forgetting the https:// scheme; passing a relative path; shell mangling `&` or spaces in the URL; copying a URL with trailing punctuation.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/e0277ac8c1409fec. Report an issue: GitHub.

Appendix: source

Thrown at web/scripts/compare-deployed-facts.mjs:105

      expected.latestPublishedRelease?.tag ?? null,
      receipt.latestPublishedRelease?.tag ?? null,
    ],
  ];
  for (const [field, expectedValue, deployedValue] of checks) {
    if (expectedValue !== deployedValue) {
      differences.push({ field, expected: expectedValue, deployed: deployedValue });
    }
  }
  return differences;
}

async function main() {
  const args = parseArgs(process.argv.slice(2));
  let baseUrl;
  try {
    baseUrl = new URL(args.baseUrl);
  } catch {
    throw new Error(`invalid --base-url: ${args.baseUrl}`);
  }
  if (!/^https?:$/.test(baseUrl.protocol)) {
    throw new Error("--base-url must use http or https");
  }

  const expectedRevision = args.expectedRevision || localRevision();
  if (!expectedRevision || !/^[0-9a-f]{40}$/i.test(expectedRevision)) {
    throw new Error("expected revision must be an exact 40-character Git SHA");
  }
  if (!Number.isInteger(args.attempts) || args.attempts < 1 || args.attempts > 20) {
    throw new Error("--attempts must be an integer from 1 to 20");
  }
  if (!Number.isFinite(args.retryDelayMs) || args.retryDelayMs < 0 || args.retryDelayMs > 30_000) {
    throw new Error("--retry-delay-ms must be between 0 and 30000");
  }

  const facts = buildFacts();
  const expected = {

View on GitHub (pinned to 433685b202)