{"record":{"id":"e36a774983e8da8d","repo":"jackwener/OpenCLI","slug":"period-is-only-valid-with-view-top","errorCode":null,"errorMessage":"--period is only valid with --view top","messagePattern":"--period is only valid with --view top","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"warning","filePath":"clis/linux-do/feed.js","lineNumber":264,"sourceCode":"    throw new ArgumentError(`Unknown tag: ${value}`, 'Use \"opencli linux-do tags\" to list available tags');\n}\n/**\n * 解析分类，并补齐父分类信息。\n */\nasync function resolveCategory(page, value) {\n    const liveCategory = findMatchingCategory(await fetchLiveCategories(page), value);\n    if (liveCategory)\n        return liveCategory;\n    throw new ArgumentError(`Unknown category: ${value}`, 'Use \"opencli linux-do categories\" to list available categories');\n}\n/**\n * 将命令参数转换为最终请求地址\n */\nasync function resolveFeedRequest(page, kwargs) {\n    const view = (kwargs.view || 'latest');\n    const period = (kwargs.period || 'weekly');\n    if (kwargs.period && view !== 'top') {\n        throw new ArgumentError('--period is only valid with --view top');\n    }\n    const params = new URLSearchParams();\n    if (kwargs.order && kwargs.order !== 'default')\n        params.set('order', kwargs.order);\n    if (kwargs.ascending)\n        params.set('ascending', 'true');\n    if (kwargs.limit)\n        params.set('per_page', String(kwargs.limit));\n    const tagValue = typeof kwargs.tag === 'string' ? kwargs.tag.trim() : '';\n    const categoryValue = typeof kwargs.category === 'string' ? kwargs.category.trim() : '';\n    if (!tagValue && !categoryValue) {\n        const query = new URLSearchParams(params);\n        if (view === 'top')\n            query.set('period', period);\n        const jsonSuffix = query.toString() ? `?${query.toString()}` : '';\n        return {\n            url: `${view === 'latest' ? '/latest.json' : view === 'hot' ? '/hot.json' : '/top.json'}${jsonSuffix}`,\n        };","sourceCodeStart":246,"sourceCodeEnd":282,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linux-do/feed.js#L246-L282","documentation":"resolveFeedRequest converts CLI flags into a linux.do feed URL. The --period flag is only meaningful for the 'top' view, which selects a time window (e.g. daily/weekly/monthly); for other views (latest, new, etc.) period makes no sense, so the library rejects the combination up front with an ArgumentError rather than silently ignoring the flag.","triggerScenarios":"Calling the feed command (or request() which calls resolveFeedRequest) with kwargs.period set while kwargs.view is absent or anything other than 'top' — e.g. `--period monthly` alone, or `--view latest --period daily`.","commonSituations":"Users copying a 'top period' example but forgetting `--view top`; scripts defaulting view to 'latest'; help text that does not make the coupling obvious.","solutions":["Add `--view top` alongside `--period <value>`.","Drop the `--period` flag if a non-top view is intended.","Validate in the caller that view === 'top' whenever period is provided."],"exampleFix":"// before\ncli --site linux-do --name feed --period monthly\n// after\ncli --site linux-do --name feed --view top --period monthly","handlingStrategy":"validation","validationCode":"if (args.period && (args.view ?? 'latest') !== 'top') {\n  throw new Error('--period is only valid with --view top');\n}","typeGuard":"const isTopView = (v) => v === 'top';","tryCatchPattern":"try {\n  await request(page, kwargs);\n} catch (e) {\n  if (e.name === 'ArgumentError' && /--period/.test(e.message)) {\n    console.error('Add --view top when using --period.');\n  } else throw e;\n}","preventionTips":["Pair --period only with --view top","Add pre-flight flag validation in wrapper scripts","Read `--help` for view/period coupling"],"tags":["cli","argument-validation","flags"],"backgroundTag":"invalid-argument-combination","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}