{"record":{"id":"35a5ce9570852255","repo":"jackwener/OpenCLI","slug":"bilibili-unfollow-target-cannot-be-empty","errorCode":null,"errorMessage":"bilibili unfollow target cannot be empty","messagePattern":"bilibili unfollow target cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/bilibili/unfollow.js","lineNumber":15,"sourceCode":"/**\n * Bilibili unfollow — removes a follow relation via the official write API.\n * Mirror of follow.js with act=2. If the viewer is not currently following the\n * target, the API call is skipped and `not-following` is returned without\n * touching state.\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\nasync function resolveTargetMid(page, raw) {\n    const trimmed = String(raw ?? '').trim();\n    if (!trimmed) {\n        throw new ArgumentError('bilibili unfollow 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 unfollow 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":1,"sourceCodeEnd":33,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/bilibili/unfollow.js#L1-L33","documentation":"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.","triggerScenarios":"Calling `bilibili unfollow` without the positional target argument, passing an empty string, or programmatically invoking resolveTargetMid/mid with an unset variable.","commonSituations":"Shell scripts where the target variable is unquoted or unset; missing required-arg validation upstream; copy-paste commands with the UID omitted.","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."],"exampleFix":"// before\nconst target = process.env.BILI_TARGET;\nawait run('bilibili', 'unfollow', target); // may be undefined\n// after\nconst target = process.env.BILI_TARGET;\nif (!target || !target.trim()) throw new Error('BILI_TARGET is required');\nawait run('bilibili', 'unfollow', target.trim());","handlingStrategy":"validation","validationCode":"const trimmed = String(rawTarget ?? '').trim();\nif (!trimmed) throw new Error('unfollow target (UID or space.bilibili.com URL) is required');","typeGuard":"function isValidUnfollowTarget(raw) {\n  const t = String(raw ?? '').trim();\n  return t.length > 0 && (/^\\d+$/.test(t) || /^(?:https?:\\/\\/)?space\\.bilibili\\.com\\//i.test(t));\n}","tryCatchPattern":"try {\n  await unfollow(page, target);\n} catch (e) {\n  if (String(e.message).includes('target cannot be empty')) {\n    console.error('Usage: bilibili unfollow <uid | space.bilibili.com/<uid> URL>');\n    process.exitCode = 2;\n  } else throw e;\n}","preventionTips":["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"],"tags":["bilibili","argument-validation","input-validation","cli"],"backgroundTag":"missing-required-argument","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}