jackwener/OpenCLI · error · ArgumentError
weibo delete: URL must use http or https
Error message
weibo delete: URL must use http or https
What it means
If the id argument parses as a URL, normalizePostId requires it to use http: or https:. Any other scheme (ftp:, javascript:, weibo://, or a malformed string that URL still accepts like 'foo:bar') is rejected with ArgumentError to avoid resolving ids from non-web schemes.
Source
Thrown at clis/weibo/delete.js:21
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, AuthRequiredError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { requireObjectEvaluateResult, unwrapEvaluateResult } from './utils.js';
const WEIBO_HOST_RE = /(^|\.)weibo\.(com|cn)$/i;
const POST_ID_RE = /^[A-Za-z0-9]{4,32}$/;
function normalizePostId(raw) {
const input = String(raw ?? '').trim();
if (!input) {
throw new ArgumentError('weibo delete: id cannot be empty');
}
let candidate = input;
try {
const url = new URL(input);
if (url.protocol !== 'http:' && url.protocol !== 'https:') {
throw new ArgumentError('weibo delete: URL must use http or https');
}
if (!WEIBO_HOST_RE.test(url.hostname)) {
throw new ArgumentError('weibo delete: URL must be a weibo.com or weibo.cn post URL');
}
const parts = url.pathname.split('/').filter(Boolean);
if (url.hostname.toLowerCase().endsWith('weibo.cn') && parts[0] === 'status') {
candidate = parts[1] ?? '';
} else {
candidate = parts.at(-1) ?? '';
}
} catch (error) {
if (error instanceof ArgumentError) throw error;
}
candidate = String(candidate ?? '').trim();
if (!POST_ID_RE.test(candidate)) {
throw new ArgumentError('weibo delete: id must be a numeric idstr, mblogid, or Weibo post URL');
}View on GitHub (pinned to 49907e53dc)
Solutions
- Use a full https:// URL, e.g. https://weibo.com/1234567890/AbCdEfGhI
- Or pass just the id (idstr or mblogid) instead of a URL — no scheme issues
- Fix typos in the scheme (https:// not htp:// or http:/ )
Example fix
// before weibo delete --id 'weibo.com/user/AbCdEfGhI' // after weibo delete --id 'https://weibo.com/user/AbCdEfGhI'
Defensive patterns
Strategy: validation
Validate before calling
function hasHttpScheme(u) {
try { const url = new URL(u); return url.protocol === 'http:' || url.protocol === 'https:'; }
catch { return false; }
}
if (!hasHttpScheme(input) && input.includes(':')) throw new Error('URL must use http or https'); Type guard
function isHttpUrl(v) {
if (typeof v !== 'string') return false;
try { const u = new URL(v); return u.protocol === 'http:' || u.protocol === 'https:'; }
catch { return false; }
} Try / catch
try {
await cliDelete({ id: input });
} catch (err) {
if (err instanceof ArgumentError && /must use http or https/.test(err.message)) {
throw new Error('Use a full https:// URL or pass the bare id instead');
} else throw err;
} Prevention
- Prefer passing the bare id over a URL to avoid scheme parsing entirely
- Always include the full https:// prefix when passing URLs
- Don't paste custom-scheme links from the Weibo mobile app
- Sanitize inputs in wrapper scripts to strip stray schemes
When it happens
Trigger: Passing a URL-like string with a non-http(s) scheme, e.g. `weibo delete --id 'weibo.com/123'` parsed with a relative scheme, or accidentally passing an internal/app scheme link copied from a mobile client.
Common situations: Pasting a link from the Weibo mobile app that uses a custom scheme, omitting the protocol and having URL parse it oddly, or typo'd schemes like htp://.
Related errors
- 1688 item expects an offer URL or offer ID
- Invalid 1688 store URL
- Invalid 1688 URL
- Expected an exact BVID or bilibili.com video URL, for exampl
- Expected a trusted HTTPS bilibili.com video URL without cred
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/e1a9ef11437b9fa1.
Report an issue: GitHub.