{"record":{"id":"44551d5aef1b7b91","repo":"jackwener/OpenCLI","slug":"stackoverflow-related-sort-must-be-one-of-sort-o","errorCode":null,"errorMessage":"stackoverflow related sort must be one of ${SORT_OPTIONS.join(', ')}","messagePattern":"stackoverflow related sort must be one of (.+?)","errorType":"validation","errorClass":"ArgumentError","httpStatus":null,"severity":"error","filePath":"clis/stackoverflow/related.js","lineNumber":40,"sourceCode":"    access: 'read',\n    description: 'List Stack Overflow questions related to a given question id.',\n    domain: 'stackoverflow.com',\n    strategy: Strategy.PUBLIC,\n    browser: false,\n    args: [\n        { name: 'id', positional: true, required: true, type: 'string', help: 'Stack Overflow question id (numeric, e.g. 79935770).' },\n        { name: 'sort', type: 'string', default: 'rank', help: `Sort key: ${SORT_OPTIONS.join(', ')} (rank = SO relevance default).` },\n        { name: 'limit', type: 'int', default: 20, help: 'Max related questions (1-100).' },\n    ],\n    columns: ['rank', 'id', 'title', 'score', 'answers', 'views', 'isAnswered', 'tags', 'author', 'createdAt', 'lastActivityAt', 'url'],\n    func: async (args) => {\n        const id = String(args.id ?? '').trim();\n        if (!/^\\d+$/.test(id)) {\n            throw new ArgumentError(`stackoverflow related id must be a numeric question id, got ${JSON.stringify(args.id)}`);\n        }\n        const sort = String(args.sort ?? 'rank').toLowerCase();\n        if (!SORT_OPTIONS.includes(sort)) {\n            throw new ArgumentError(`stackoverflow related sort must be one of ${SORT_OPTIONS.join(', ')}`);\n        }\n        const limit = normalizeLimit(args.limit, 20, 100, 'limit');\n        const data = await seFetch(`/questions/${encodeURIComponent(id)}/related`, {\n            searchParams: {\n                order: 'desc',\n                sort,\n                pagesize: limit,\n            },\n        });\n        const items = ensureItems(data, `stackoverflow related ${id}`);\n        return items.slice(0, limit).map((q, i) => ({\n            rank: i + 1,\n            id: q.question_id,\n            title: decodeHtmlEntities(q.title || ''),\n            score: q.score ?? 0,\n            answers: q.answer_count ?? 0,\n            views: q.view_count ?? 0,\n            isAnswered: Boolean(q.is_answered),","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/stackoverflow/related.js#L22-L58","documentation":"ArgumentError from `stackoverflow related` when the `sort` flag is not one of the accepted keys (rank, activity, votes, creation). The value is lowercased first, so case is not the problem — only an unknown sort key triggers this. The check runs before the API call to fail fast on invalid input.","triggerScenarios":"`stackoverflow related <id> --sort relevance`, `--sort score`, `--sort newest`, or any other key outside SORT_OPTIONS = ['rank','activity','votes','creation'].","commonSituations":"Assuming related shares sort keys with the `tag` command or the generic /questions endpoint (which uses 'activity', 'votes', 'creation' but not 'rank'); guessing sort names from the SE web UI ('relevance', 'newest'); typos like 'vote' or 'creat'.","solutions":["Use one of: rank, activity, votes, creation (e.g. `stackoverflow related 79935770 --sort votes`).","Check `stackoverflow related --help` for the current sort key list.","If you want relevance ordering, use the default (omit --sort, which defaults to 'rank')."],"exampleFix":"// before\nstackoverflow related 79935770 --sort relevance\n// after\nstackoverflow related 79935770 --sort rank","handlingStrategy":"validation","validationCode":"const SORTS = ['rank', 'activity', 'votes', 'creation'];\nif (!SORTS.includes(String(sort).toLowerCase())) throw new TypeError(`sort must be one of ${SORTS.join(', ')}`);","typeGuard":null,"tryCatchPattern":"try {\n  await related(id, { sort });\n} catch (e) {\n  if (e.name === 'ArgumentError' && e.message.includes('sort must be one of')) {\n    console.error(`${sort} is invalid; use rank|activity|votes|creation`);\n    process.exitCode = 2;\n    return;\n  }\n  throw e;\n}","preventionTips":["Whitelist sort values in wrapper scripts using the same list as the CLI.","Use the command's --help output rather than guessing sort keys.","Note 'related' uses 'rank' (not 'relevance'); the 'tag' command has a different option set."],"tags":["argument-validation","cli","invalid-option"],"backgroundTag":"invalid-option-value","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}