{"record":{"id":"0a4acb3134f4d497","repo":"DIYgod/RSSHub","slug":"error-0a4acb","errorCode":null,"errorMessage":"关键词不能为空","messagePattern":"关键词不能为空","errorType":"exception","errorClass":"Error","httpStatus":503,"severity":"warning","filePath":"lib/routes/asianfanfics/text-search.ts","lineNumber":32,"sourceCode":"    parameters: {\n        keyword: '关键词',\n    },\n    name: '关键词',\n    maintainers: ['KazooTTT'],\n    radar: [\n        {\n            source: ['www.asianfanfics.com/browse/text_search?q=:keyword'],\n            target: '/text-search/:keyword',\n        },\n    ],\n    description: '匹配 asianfanfics 搜索关键词',\n    handler,\n};\n\nasync function handler(ctx) {\n    const keyword = ctx.req.param('keyword');\n    if (keyword.trim() === '') {\n        throw new Error('关键词不能为空');\n    }\n    const link = `https://www.asianfanfics.com/browse/text_search?q=${keyword}+`;\n\n    const response = await ofetch(link, {\n        headers: {\n            'user-agent': config.trueUA,\n        },\n    });\n    const $ = load(response);\n\n    const items: DataItem[] = $('.primary-container .excerpt')\n        .toArray()\n        .filter((element) => {\n            const $element = $(element);\n            return $element.find('.excerpt__title a').length > 0;\n        })\n        .map((element) => {\n            const $element = $(element);","sourceCodeStart":14,"sourceCodeEnd":50,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/asianfanfics/text-search.ts#L14-L50","documentation":"Thrown by the asianfanfics text-search route when the :keyword path parameter is empty or whitespace-only. The handler trims the keyword before building the search URL, so a blank keyword is rejected before the ofetch is made.","triggerScenarios":"Requesting /asianfanfics/text-search/ with no keyword, or with a keyword that is only spaces (URL-decoded to whitespace).","commonSituations":"Malformed RSS reader URL; user clears the keyword field; trailing slash route matching yields an empty param.","solutions":["Supply a non-empty keyword, e.g. /asianfanfics/text-search/fluff.","If empty-search behavior is desired, change the guard to return an empty feed instead of throwing."],"exampleFix":"// before\nif (keyword.trim() === '') {\n    throw new Error('关键词不能为空');\n}\n\n// after\nif (!keyword?.trim()) {\n    throw new InvalidParameterError('Keyword must not be empty');\n}","handlingStrategy":"validation","validationCode":"const keyword = String(ctx.req.param('keyword') ?? '').trim();\nif (!keyword) {\n    throw new InvalidParameterError('Keyword must not be empty');\n}","typeGuard":"function isNonEmptyKeyword(v: unknown): v is string {\n    return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":null,"preventionTips":["Coalesce undefined to '' with ?? before trimming to avoid runtime errors on missing params.","Use InvalidParameterError for user-input failures."],"tags":["asianfanfics","input-validation","route-parameter","i18n"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}