jackwener/OpenCLI · error · ArgumentError

xiaoe URL must use https (got ${parsed.protocol.replace(':',

Error message

xiaoe URL must use https (got ${parsed.protocol.replace(':', '')})

What it means

After parsing, requireXiaoePageUrl enforces the https protocol. If parsed.protocol !== 'https:' it throws ArgumentError telling you which scheme was received, with the expected URL format as the hint.

Source

Thrown at clis/xiaoe/content.js:95

    return count;
}

export function requireXiaoePageUrl(value, commandName) {
    const raw = typeof value === 'string' ? value.trim() : '';
    if (!raw) {
        throw new ArgumentError('url is required (positional)');
    }
    let parsed;
    try {
        parsed = new URL(raw);
    } catch {
        throw new ArgumentError(
            `invalid xiaoe URL: ${raw}`,
            `Example: opencli xiaoe ${commandName} https://appxxxx.h5.xet.citv.cn/p/course/ecourse/v_xxxxx`,
        );
    }
    if (parsed.protocol !== 'https:') {
        throw new ArgumentError(
            `xiaoe URL must use https (got ${parsed.protocol.replace(':', '')})`,
            `Example: opencli xiaoe ${commandName} https://appxxxx.h5.xet.citv.cn/p/course/ecourse/v_xxxxx`,
        );
    }
    const host = parsed.hostname.toLowerCase();
    if (host !== 'h5.xet.citv.cn' && !host.endsWith('.h5.xet.citv.cn')) {
        throw new ArgumentError(
            `url must be on h5.xet.citv.cn or a shop subdomain (got ${parsed.hostname})`,
            `Example: opencli xiaoe ${commandName} https://appxxxx.h5.xet.citv.cn/p/course/ecourse/v_xxxxx`,
        );
    }
    return parsed.toString();
}

export function buildContentScript() {
    return `
(() => {
  ${pickContentText.toString()}

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Replace the scheme with https:// before invoking the command.
  2. If a site redirects http→https, use the final https URL directly.
  3. Never pass local file:// paths; load saved pages through a local https server if needed.
  4. Pre-validate the scheme with new URL(raw).protocol === 'https:' in calling code.

Example fix

// before
opencli xiaoe content 'http://appxxxx.h5.xet.citv.cn/p/course/ecourse/v_xxxxx'
// after
opencli xiaoe content 'https://appxxxx.h5.xet.citv.cn/p/course/ecourse/v_xxxxx'
Defensive patterns

Strategy: validation

Validate before calling

const u = new URL(raw);
if (u.protocol !== 'https:') throw new Error(`use https, got ${u.protocol}`);

Type guard

const isHttps = v => { try { return new URL(v).protocol === 'https:'; } catch { return false; } };

Try / catch

try {
  await contentCommand(url);
} catch (e) {
  if (e instanceof ArgumentError && /must use https/.test(e.message)) {
    url = url.replace(/^http:\/\//, 'https://');
    await contentCommand(url);
  } else throw e;
}

Prevention

When it happens

Trigger: Supplying an http://, file://, or other non-https URL as the positional url to a xiaoe content command.

Common situations: Copy-pasting an http:// link from old documentation or an internal mirror; using a file:// path for a saved page; Xiaoe-hosted pages always requiring TLS so http links would fail anyway.

Related errors


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