jackwener/OpenCLI · error · ArgumentError
who 不能为空
Error message
who 不能为空
What it means
ArgumentError thrown by the 1point3acres user command when the `who` argument is missing or an empty/whitespace string. `who` accepts either a numeric uid or a username and is required to build the space profile URL, so the CLI fails fast with a hint (传用户名或数字 uid) telling the caller to supply one.
Source
Thrown at clis/1point3acres/user.js:29
cli({
site: '1point3acres',
name: 'user',
access: 'read',
description: '一亩三分地 用户空间(用户组 / 积分 / 大米 / 帖子数 等)',
domain: 'www.1point3acres.com',
strategy: Strategy.PUBLIC,
browser: false,
args: [
{ name: 'who', required: true, positional: true, help: '用户名或 uid(纯数字按 uid 查,否则按用户名)' },
],
columns: [
'uid', 'username', 'group', 'credits', 'rice',
'posts', 'threads', 'digests', 'registerTime', 'lastAccess', 'profileUrl',
],
func: async (args) => {
const who = String(args.who || '').trim();
if (!who) throw new ArgumentError('who 不能为空', '传用户名或数字 uid');
const url = /^\d+$/.test(who)
? `${BASE}/space-uid-${who}.html`
: `${BASE}/space-username-${encodeURIComponent(who)}.html`;
const html = await fetchHtml(url);
if (/<title>提示信息/.test(html) && /(没有找到|不存在)/.test(html)) {
throw new EmptyResultError('1point3acres user', `用户 "${who}" 不存在`);
}
const pick = (re) => {
const m = html.match(re);
return m ? decodeEntities(m[1].trim()) : '';
};
// <li>KEY: VAL</li> — tolerant of optional <span>, colons fullwidth/半角, 颗/根/粒 suffixes.
const pickLi = (label) => {
const re = new RegExp(`<li>\\s*${label}[::\\s]*(?:<[^>]+>)?\\s*([^<]+?)\\s*(?:<|$)`);
const m = html.match(re);
return m ? decodeEntities(m[1].trim()) : '';View on GitHub (pinned to 49907e53dc)
Solutions
- Provide `who` as either a numeric uid (e.g. '363088') or a username string
- Trim the value before calling if it comes from user input or env
- Add an upstream check: if (!who) prompt for the username instead of calling
- Note usernames are passed through encodeURIComponent — no need to pre-encode, but the raw value must be non-empty
Example fix
// before
user({ who: process.env.TARGET }) // TARGET unset → ArgumentError
// after
if (!process.env.TARGET) throw new Error('TARGET must be a username or uid');
user({ who: process.env.TARGET.trim() }) Defensive patterns
Strategy: validation
Validate before calling
const who = String(input ?? '').trim();
if (!who) throw new Error('who is required: a username or numeric uid'); Type guard
const hasWho = (v) => typeof v === 'string' && v.trim().length > 0;
Try / catch
try {
await user({ who });
} catch (e) {
if (e instanceof ArgumentError) {
console.error('Pass who as a username or numeric uid, e.g. user({ who: "jason" }) or user({ who: "363088" })');
} else throw e;
} Prevention
- Validate/trim `who` at the CLI/UI boundary before invoking
- Guard upstream variables that may be undefined
- Prefer numeric uid when the username may contain special characters
When it happens
Trigger: Calling the user command without `who`, with an empty string, or with a value that trims to nothing (e.g. who: ' ').
Common situations: Forgot to pass the argument in a script; a variable upstream that resolved to '' or undefined; shell variable unquoted/empty in a CLI pipeline.
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
- keyword must not be empty
- <from> station must not be empty
- <to> station must not be empty
- key is required
- ${label} is required (YYYY-MM-DD)
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/741cb4c80b4b47be.
Report an issue: GitHub.