{"record":{"id":"b357a48e8d73c9ea","repo":"jackwener/OpenCLI","slug":"xianyu-publish-label-cannot-be-empty","errorCode":null,"errorMessage":"xianyu publish ${label} cannot be empty","messagePattern":"xianyu publish (.+?) cannot be empty","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/xianyu/publish.js","lineNumber":29,"sourceCode":"    return 'https://www.goofish.com/publish';\n}\n\nasync function getCurrentPageUrl(page) {\n    if (page.getCurrentUrl) {\n        try {\n            const currentUrl = await page.getCurrentUrl();\n            if (currentUrl) return currentUrl;\n        } catch {\n            // Best-effort URL is only used for operator diagnostics after submit.\n        }\n    }\n    return buildPublishUrl();\n}\n\nfunction requireText(value, label) {\n    const text = String(value ?? '').replace(/\\s+/g, ' ').trim();\n    if (!text) {\n        throw new ArgumentError(`xianyu publish ${label} cannot be empty`);\n    }\n    return text;\n}\n\nfunction parsePositivePrice(value, label) {\n    if (value == null || String(value).trim() === '') {\n        return null;\n    }\n    const text = String(value).trim();\n    if (!/^\\d+(?:\\.\\d{1,2})?$/.test(text)) {\n        throw new ArgumentError(`xianyu publish ${label} must be a positive price with at most 2 decimals`);\n    }\n    const price = Number(text);\n    if (!Number.isFinite(price) || price <= 0) {\n        throw new ArgumentError(`xianyu publish ${label} must be a positive price`);\n    }\n    return text;\n}","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/xianyu/publish.js#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait publish({ title: draft.title }); // draft.title may be ''\n\n// after\nconst title = (draft.title ?? '').trim();\nif (!title) throw new Error('draft has no title — cannot publish');\nawait publish({ title });","handlingStrategy":"validation","validationCode":"for (const [label, v] of Object.entries({ title, description })) {\n  if (!String(v ?? '').trim()) throw new Error(`publish field '${label}' must be a non-empty string`);\n}","typeGuard":"function isNonEmptyText(v) { return typeof v === 'string' && v.trim().length > 0; }","tryCatchPattern":"try {\n  await publish(args);\n} catch (e) {\n  if (e instanceof ArgumentError && /cannot be empty/.test(e.message)) {\n    const field = e.message.match(/publish (.+) cannot be empty/)?.[1];\n    console.error(`Missing required publish field: ${field}`);\n  } else throw e;\n}","preventionTips":["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."],"tags":["argument-validation","xianyu","input-validation"],"backgroundTag":"missing-required-field","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}