jackwener/OpenCLI · error · ArgumentError
xianyu publish ${label} cannot be empty
Error message
xianyu publish ${label} cannot be empty What it means
The `xianyu publish` helper's requireText() normalizes a required field (title, description, condition label, etc.) by trimming and collapsing whitespace; if the result is empty, it throws ArgumentError `xianyu publish ${label} cannot be empty` at clis/xianyu/publish.js:29. The library refuses to open the publish flow with blank required fields, since Goofish would reject them anyway.
Source
Thrown at clis/xianyu/publish.js:29
return 'https://www.goofish.com/publish';
}
async function getCurrentPageUrl(page) {
if (page.getCurrentUrl) {
try {
const currentUrl = await page.getCurrentUrl();
if (currentUrl) return currentUrl;
} catch {
// Best-effort URL is only used for operator diagnostics after submit.
}
}
return buildPublishUrl();
}
function requireText(value, label) {
const text = String(value ?? '').replace(/\s+/g, ' ').trim();
if (!text) {
throw new ArgumentError(`xianyu publish ${label} cannot be empty`);
}
return text;
}
function parsePositivePrice(value, label) {
if (value == null || String(value).trim() === '') {
return null;
}
const text = String(value).trim();
if (!/^\d+(?:\.\d{1,2})?$/.test(text)) {
throw new ArgumentError(`xianyu publish ${label} must be a positive price with at most 2 decimals`);
}
const price = Number(text);
if (!Number.isFinite(price) || price <= 0) {
throw new ArgumentError(`xianyu publish ${label} must be a positive price`);
}
return text;
}View on GitHub (pinned to 49907e53dc)
Solutions
- Provide a non-empty value for the flagged field (the message names it via ${label}, e.g. 'xianyu publish title cannot be empty').
- Trim and validate inputs in your caller before invoking publish.
- Check that config/env values feeding these fields are actually populated, not empty strings.
- Add required-field validation at your app's input boundary with a clear user-facing error.
- If a field should be optional, don't pass null/'' — pass a sensible default.
Example fix
// before
await publish({ title: draft.title }); // draft.title may be ''
// after
const title = (draft.title ?? '').trim();
if (!title) throw new Error('draft has no title — cannot publish');
await publish({ title }); Defensive patterns
Strategy: validation
Validate before calling
for (const [label, v] of Object.entries({ title, description })) {
if (!String(v ?? '').trim()) throw new Error(`publish field '${label}' must be a non-empty string`);
} Type guard
function isNonEmptyText(v) { return typeof v === 'string' && v.trim().length > 0; } Try / catch
try {
await publish(args);
} catch (e) {
if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {
const field = e.message.match(/publish (.+) cannot be empty/)?.[1];
console.error(`Missing required publish field: ${field}`);
} else throw e;
} Prevention
- Trim and check required text fields at your app's input boundary.
- Watch for empty-string env/config values — they pass null checks but fail here.
- Give defaults for optional-looking fields instead of passing undefined.
- Surface field names from the error message back to users.
When it happens
Trigger: Calling the publish command/normalizePublishArgs with a null, undefined, empty string, or whitespace-only value for a required text field — e.g. publish({ title: ' ' }) or a missing --description flag; condition producing an empty label via requireText.
Common situations: Config/env variables that are set but empty ('' from unset CI secrets); a form/JSON input where optional-looking fields were omitted; whitespace-only values from copy-pasted templates; code paths passing undefined because an upstream object lacked the key.
Understand the failure class
Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.
Related errors
- xianyu publish ${label} must be a positive price with at mos
- ${label} must be a non-negative integer, got ${JSON.stringif
- limit must be a positive integer
- archive wayback timestamp must be YYYY[MM[DD[hh[mm[ss]]]]] o
- archive wayback url cannot be empty
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/b357a48e8d73c9ea.
Report an issue: GitHub.