{"record":{"id":"b6ceda5cd1d8461e","repo":"DIYgod/RSSHub","slug":"invalid-k-k-k","errorCode":null,"errorMessage":"Invalid k: k=${k}","messagePattern":"Invalid k: k=(.+?)","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"warning","filePath":"lib/routes/misskon/top.ts","lineNumber":49,"sourceCode":"            target: '/top/7',\n        },\n        {\n            title: 'Top 30 days',\n            source: ['misskon.com/top30/'],\n            target: '/top/30',\n        },\n        {\n            title: 'Top 60 days',\n            source: ['misskon.com/top60/'],\n            target: '/top/60',\n        },\n    ],\n    name: 'Top k days',\n    maintainers: ['Urabartin'],\n    handler: async (ctx) => {\n        const { k } = ctx.req.param();\n        if (!['3', '7', '30', '60'].includes(k)) {\n            throw new Error(`Invalid k: k=${k}`);\n        }\n        const topLink = `https://misskon.com/top${k}/`;\n        const response = await ofetch(topLink);\n        const $ = load(response);\n\n        const feedTitle = $('.page-title').text();\n        const feedDesc = $('.content > p').first().text();\n        const itemSlugs = $('#main-content article.item-list > h2 a')\n            .toArray()\n            .map((link) => new URL($(link).attr('href') || '').pathname.slice(1, -1));\n        const searchParams = new URLSearchParams();\n        searchParams.set('slug', itemSlugs.join(','));\n        searchParams.set('per_page', itemSlugs.length.toString());\n        return {\n            title: `MissKON - ${feedTitle}`,\n            link: topLink,\n            description: feedDesc,\n            item: await getPosts(searchParams),","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/misskon/top.ts#L31-L67","documentation":"Thrown by the MissKON 'top k days' route when :k is not one of '3','7','30','60'. It is a bare `throw new Error` (not an InvalidParameterError), so it surfaces as a generic error rather than RSSHub's structured invalid-parameter response. The route only supports four pre-defined windows that map to misskon.com/topN/ pages.","triggerScenarios":"Caller requests /misskon/top/<k> with k = '10', '100', '0', or any non-whitelisted value. The includes() check fails and it throws before fetching.","commonSituations":"User guesses a value (e.g. /misskon/top/10); URL builder defaults k incorrectly; user passes an empty or negative number.","solutions":["Use one of the supported values: /misskon/top/3, /misskon/top/7, /misskon/top/30, or /misskon/top/60.","If you maintain the route, consider throwing InvalidParameterError instead of a bare Error so the response is structured.","Validate k in any client before constructing the feed URL."],"exampleFix":"// before\nif (!['3', '7', '30', '60'].includes(k)) {\n    throw new Error(`Invalid k: k=${k}`);\n}\n\n// after — use the structured error type\nimport InvalidParameterError from '@/errors/types/invalid-parameter';\nif (!['3', '7', '30', '60'].includes(k)) {\n    throw new InvalidParameterError(`Invalid k: k=${k}. Must be one of 3, 7, 30, 60.`);\n}","handlingStrategy":"validation","validationCode":"const { k } = ctx.req.param();\nif (!['3', '7', '30', '60'].includes(k)) {\n    throw new InvalidParameterError(`k must be one of 3, 7, 30, 60; got: ${k}`);\n}","typeGuard":"function isValidK(k: string): k is '3' | '7' | '30' | '60' {\n    return ['3', '7', '30', '60'].includes(k);\n}","tryCatchPattern":null,"preventionTips":["Use the structured InvalidParameterError instead of a bare Error for consistent client responses.","Mirror the valid set in the route's parameter description so users see it in docs.","Constrain :k in any feed-URL builder with a dropdown, not free text."],"tags":["invalid-parameter","validation","enum","misskon"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}