DIYgod/RSSHub · warning · Error
关键词不能为空
Error message
关键词不能为空
What it means
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.
Source
Thrown at lib/routes/asianfanfics/text-search.ts:32
parameters: {
keyword: '关键词',
},
name: '关键词',
maintainers: ['KazooTTT'],
radar: [
{
source: ['www.asianfanfics.com/browse/text_search?q=:keyword'],
target: '/text-search/:keyword',
},
],
description: '匹配 asianfanfics 搜索关键词',
handler,
};
async function handler(ctx) {
const keyword = ctx.req.param('keyword');
if (keyword.trim() === '') {
throw new Error('关键词不能为空');
}
const link = `https://www.asianfanfics.com/browse/text_search?q=${keyword}+`;
const response = await ofetch(link, {
headers: {
'user-agent': config.trueUA,
},
});
const $ = load(response);
const items: DataItem[] = $('.primary-container .excerpt')
.toArray()
.filter((element) => {
const $element = $(element);
return $element.find('.excerpt__title a').length > 0;
})
.map((element) => {
const $element = $(element);View on GitHub (pinned to bed535e087)
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.
Example fix
// before
if (keyword.trim() === '') {
throw new Error('关键词不能为空');
}
// after
if (!keyword?.trim()) {
throw new InvalidParameterError('Keyword must not be empty');
} Defensive patterns
Strategy: validation
Validate before calling
const keyword = String(ctx.req.param('keyword') ?? '').trim();
if (!keyword) {
throw new InvalidParameterError('Keyword must not be empty');
} Type guard
function isNonEmptyKeyword(v: unknown): v is string {
return typeof v === 'string' && v.trim().length > 0;
} Prevention
- Coalesce undefined to '' with ?? before trimming to avoid runtime errors on missing params.
- Use InvalidParameterError for user-input failures.
When it happens
Trigger: Requesting /asianfanfics/text-search/ with no keyword, or with a keyword that is only spaces (URL-decoded to whitespace).
Common situations: Malformed RSS reader URL; user clears the keyword field; trailing slash route matching yields an empty param.
Related errors
- 无效的排序类型
- Invalid language: ${language}. Allowed values are: ${[...val
- 暂不支持对${type}的订阅
- Unsupported server
- Tag not found
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/0a4acb3134f4d497.
Report an issue: GitHub.