jackwener/OpenCLI · error · ArgumentError
bilibili unfollow target cannot be empty
Error message
bilibili unfollow target cannot be empty
What it means
resolveTargetMid validates the raw unfollow target before resolving it to a user mid. An empty/blank input (null, undefined, whitespace) throws this ArgumentError immediately, since there is nothing to resolve into a space.bilibili.com mid.
Source
Thrown at clis/bilibili/unfollow.js:15
/**
* Bilibili unfollow — removes a follow relation via the official write API.
* Mirror of follow.js with act=2. If the viewer is not currently following the
* target, the API call is skipped and `not-following` is returned without
* touching state.
*/
import { cli, Strategy } from '@jackwener/opencli/registry';
import { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';
import { parseSpaceMidUrl, fetchRelationAttribute, waitForRelation } from './relation.js';
import { apiPost, getSelfUid, requireOkPayload, resolveUid } from './utils.js';
async function resolveTargetMid(page, raw) {
const trimmed = String(raw ?? '').trim();
if (!trimmed) {
throw new ArgumentError('bilibili unfollow target cannot be empty');
}
if (/^(?:https?:\/\/)?space\.bilibili\.com\//i.test(trimmed)) {
const mid = parseSpaceMidUrl(trimmed);
if (!mid) {
throw new ArgumentError('bilibili unfollow target must be a valid space.bilibili.com/<uid> URL');
}
return mid;
}
try {
return await resolveUid(page, trimmed);
} catch (error) {
if (error instanceof EmptyResultError) throw error;
throw new ArgumentError(
`Cannot resolve Bilibili target from input: ${trimmed}`,
error instanceof Error ? error.message : String(error),
);
}
}View on GitHub (pinned to 49907e53dc)
Solutions
- Pass a non-empty target: a numeric UID or a space.bilibili.com/<uid> URL.
- Quote the argument in shell scripts: bilibili unfollow "$TARGET".
- Add a required check on the argument before invoking the command.
- Echo the variable in scripts to confirm it is populated before the call.
- If wrapping the API, validate input with a trim/length check first.
Example fix
// before
const target = process.env.BILI_TARGET;
await run('bilibili', 'unfollow', target); // may be undefined
// after
const target = process.env.BILI_TARGET;
if (!target || !target.trim()) throw new Error('BILI_TARGET is required');
await run('bilibili', 'unfollow', target.trim()); Defensive patterns
Strategy: validation
Validate before calling
const trimmed = String(rawTarget ?? '').trim();
if (!trimmed) throw new Error('unfollow target (UID or space.bilibili.com URL) is required'); Type guard
function isValidUnfollowTarget(raw) {
const t = String(raw ?? '').trim();
return t.length > 0 && (/^\d+$/.test(t) || /^(?:https?:\/\/)?space\.bilibili\.com\//i.test(t));
} Try / catch
try {
await unfollow(page, target);
} catch (e) {
if (String(e.message).includes('target cannot be empty')) {
console.error('Usage: bilibili unfollow <uid | space.bilibili.com/<uid> URL>');
process.exitCode = 2;
} else throw e;
} Prevention
- Mark the target argument required in CLI definitions
- Quote shell variables so empty values are not dropped silently
- Validate UID/URL format before invoking the command
- Check env/config values are populated before batch unfollow scripts
When it happens
Trigger: Calling `bilibili unfollow` without the positional target argument, passing an empty string, or programmatically invoking resolveTargetMid/mid with an unset variable.
Common situations: Shell scripts where the target variable is unquoted or unset; missing required-arg validation upstream; copy-paste commands with the UID omitted.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- bilibili comment ${label} must be a positive integer
- bilibili comment message cannot be empty
- bloomberg businessweek --limit must be an integer between 1
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/35a5ce9570852255.
Report an issue: GitHub.