jackwener/OpenCLI · error · ArgumentError
bilibili follow target cannot be empty
Error message
bilibili follow target cannot be empty
What it means
resolveTargetMid normalizes the follow target with String(raw ?? '').trim(); if the result is empty it throws this ArgumentError. The guard exists so a blank target is never forwarded to the user-search endpoint, which would return useless results.
Source
Thrown at clis/bilibili/follow.js:23
* Accepts target as: numeric uid, username, or a space.bilibili.com profile URL.
* Pre-checks the current relation so the result row reports `already-following`
* accurately instead of relying on the modify API's idempotent silent success.
*/
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';
/**
* Pull a uid out of a `space.bilibili.com/<uid>` URL before falling back to the
* generic resolver. `resolveUid` only handles bare digits or usernames; without
* this short-circuit a profile URL would get sent to the user-search endpoint
* and likely return nothing.
*/
async function resolveTargetMid(page, raw) {
const trimmed = String(raw ?? '').trim();
if (!trimmed) {
throw new ArgumentError('bilibili follow target cannot be empty');
}
if (/^(?:https?:\/\/)?space\.bilibili\.com\//i.test(trimmed)) {
const mid = parseSpaceMidUrl(trimmed);
if (!mid) {
throw new ArgumentError('bilibili follow 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: UID, username, or a space.bilibili.com/<uid> URL.
- Check the variable feeding the argument is set before invoking the CLI.
- Add a shell-level guard: [ -n "$TARGET" ] || { echo 'target required'; exit 1; }
Example fix
// before
await cli({ args: { target: process.env.TARGET } });
// after
if (!process.env.TARGET) throw new Error('TARGET env var required');
await cli({ args: { target: process.env.TARGET } }); Defensive patterns
Strategy: validation
Validate before calling
const target = (process.argv.target ?? '').trim();
if (!target) throw new Error('--target is required'); Type guard
function hasTarget(v) {
return typeof v === 'string' && v.trim().length > 0;
} Try / catch
try {
await follow(kwargs.target);
} catch (e) {
if (e instanceof ArgumentError && e.message.includes('cannot be empty')) {
console.error('Usage: bilibili follow --target <uid|username|space-url>');
process.exitCode = 2;
return;
}
throw e;
} Prevention
- Always pass --target explicitly in scripts
- Trim inputs sourced from env vars or config files
- Fail fast with a usage message when args are missing
When it happens
Trigger: Running bilibili follow without the --target argument, or passing a value that is only whitespace / an empty string after shell expansion (e.g. TARGET="" bilibili follow).
Common situations: Scripting the CLI with an unset environment variable, forgetting the required positional/flag argument, or a config file with an empty target field.
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
- archive search sort must be one of ${SORT_OPTIONS.join(', ')
- archive search mediatype must be one of ${MEDIATYPES.join(',
- archive search limit must be a positive integer
- archive search limit must be <= 100
- archive search query must not be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/19d066d022239b8b.
Report an issue: GitHub.