Hmbown/CodeWhale · error · Error

--base-url must use http or https

Error message

--base-url must use http or https

What it means

compare-deployed-facts.mjs validates its --base-url CLI option before fetching. It parses the value with `new URL()` and then requires the parsed protocol to be exactly http: or https:. Any other scheme (ftp:, file:, ws:, etc.) throws this error so the script never issues requests to an unexpected protocol.

Solutions

  1. Pass a URL that starts with http:// or https://
  2. Check for typos like htp:// or a missing scheme and fix the scheme part
  3. If targeting a non-http service, proxy it through an https endpoint instead

Example fix

// before
node web/scripts/compare-deployed-facts.mjs --base-url example.com
// after
node web/scripts/compare-deployed-facts.mjs --base-url https://example.com
Defensive patterns

Strategy: validation

Validate before calling

function isValidBaseUrl(u) { try { return /^https?:$/.test(new URL(u).protocol); } catch { return false; } }
if (!isValidBaseUrl(args.baseUrl)) throw new Error('bad --base-url');

Type guard

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

Try / catch

try { run(args); } catch (e) { if (e.message.includes('--base-url')) { console.error('Use an http:// or https:// URL'); process.exitCode = 2; } else throw e; }

Prevention

When it happens

Trigger: Running `node web/scripts/compare-deployed-facts.mjs --base-url ftp://example.com` (or file:, //missing-scheme, etc.). The URL parses successfully but `baseUrl.protocol` is not 'http:' or 'https:'.

Common situations: Pasting a deploy URL that omits the scheme, using an internal custom scheme, or copying a URL from a tool that emits protocol-relative or non-http URLs.

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/e150d504d34daff9. Report an issue: GitHub.

Appendix: source

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

  ];
  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 = {
    sourceRevision: expectedRevision,
    version: facts.version,
    providerCount: facts.providers.length,

View on GitHub (pinned to 433685b202)