{"record":{"id":"19d066d022239b8b","repo":"jackwener/OpenCLI","slug":"bilibili-follow-target-cannot-be-empty","errorCode":null,"errorMessage":"bilibili follow target cannot be empty","messagePattern":"bilibili follow target cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/follow.js","lineNumber":23,"sourceCode":" * Accepts target as: numeric uid, username, or a space.bilibili.com profile URL.\n * Pre-checks the current relation so the result row reports `already-following`\n * accurately instead of relying on the modify API's idempotent silent success.\n */\nimport { cli, Strategy } from '@jackwener/opencli/registry';\nimport { ArgumentError, CommandExecutionError, EmptyResultError } from '@jackwener/opencli/errors';\nimport { parseSpaceMidUrl, fetchRelationAttribute, waitForRelation } from './relation.js';\nimport { apiPost, getSelfUid, requireOkPayload, resolveUid } from './utils.js';\n\n/**\n * Pull a uid out of a `space.bilibili.com/<uid>` URL before falling back to the\n * generic resolver. `resolveUid` only handles bare digits or usernames; without\n * this short-circuit a profile URL would get sent to the user-search endpoint\n * and likely return nothing.\n */\nasync function resolveTargetMid(page, raw) {\n    const trimmed = String(raw ?? '').trim();\n    if (!trimmed) {\n        throw new ArgumentError('bilibili follow target cannot be empty');\n    }\n    if (/^(?:https?:\\/\\/)?space\\.bilibili\\.com\\//i.test(trimmed)) {\n        const mid = parseSpaceMidUrl(trimmed);\n        if (!mid) {\n            throw new ArgumentError('bilibili follow target must be a valid space.bilibili.com/<uid> URL');\n        }\n        return mid;\n    }\n    try {\n        return await resolveUid(page, trimmed);\n    } catch (error) {\n        if (error instanceof EmptyResultError) throw error;\n        throw new ArgumentError(\n            `Cannot resolve Bilibili target from input: ${trimmed}`,\n            error instanceof Error ? error.message : String(error),\n        );\n    }\n}","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/follow.js#L5-L41","documentation":"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.","triggerScenarios":"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).","commonSituations":"Scripting the CLI with an unset environment variable, forgetting the required positional/flag argument, or a config file with an empty target field.","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; }"],"exampleFix":"// before\nawait cli({ args: { target: process.env.TARGET } });\n// after\nif (!process.env.TARGET) throw new Error('TARGET env var required');\nawait cli({ args: { target: process.env.TARGET } });","handlingStrategy":"validation","validationCode":"const target = (process.argv.target ?? '').trim();\nif (!target) throw new Error('--target is required');","typeGuard":"function hasTarget(v) {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await follow(kwargs.target);\n} catch (e) {\n  if (e instanceof ArgumentError && e.message.includes('cannot be empty')) {\n    console.error('Usage: bilibili follow --target <uid|username|space-url>');\n    process.exitCode = 2;\n    return;\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["validation","argument-error","cli"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}