DIYgod/RSSHub · error · Error
Unhandled attribute: ${attribute}
Error message
Unhandled attribute: ${attribute} What it means
bbc/utils.tsx wraps text in <strong>/<em> based on an attribute list. Any attribute other than 'bold' or 'italic' falls through to default and throws, so a new BBC visual attribute (e.g. underline, strikethrough) surfaces immediately instead of being silently dropped.
Source
Thrown at lib/routes/bbc/utils.tsx:65
blocks?: Block[];
items?: Block[];
};
const applyAttributes = (content: JSX.Element | string, attributes?: BlockAttribute[]): JSX.Element | string => {
let result: JSX.Element | string = content;
const attributeList = attributes ?? [];
for (const attribute of attributeList) {
switch (attribute) {
case 'bold':
result = <strong>{result}</strong>;
break;
case 'italic':
result = <em>{result}</em>;
break;
default:
throw new Error(`Unhandled attribute: ${attribute}`);
}
}
return result;
};
const extractText = (blocks?: Block[]): string => {
if (!blocks?.length) {
return '';
}
return blocks
.map((block) => {
if (block.type === 'fragment') {
return block.model?.text ?? '';
}
if (block.model?.text) {
return block.model.text;View on GitHub (pinned to bed535e087)
Solutions
- Inspect the failing block in the BBC API response to see the new attribute string.
- Add a case for the new attribute (e.g. 'underline' -> <u>, 'strikethrough' -> <s>) in the switch at lib/routes/bbc/utils.tsx:54.
- If unsure how to render it, add a case returning the unmodified result instead of throwing.
Example fix
// before
case 'italic': result = <em>{result}</em>; break;
default: throw new Error(`Unhandled attribute: ${attribute}`);
// after
case 'italic': result = <em>{result}</em>; break;
case 'underline': result = <u>{result}</u>; break;
default: return result; Defensive patterns
Strategy: fallback
Validate before calling
const KNOWN_ATTRIBUTES = new Set(['bold', 'italic']);
function allAttributesKnown(attrs: string[] = []): boolean {
return attrs.every((a) => KNOWN_ATTRIBUTES.has(a));
} Type guard
const isKnownAttribute = (a: unknown): boolean => a === 'bold' || a === 'italic';
Try / catch
try {
return wrapWithAttributes(result, attributes);
} catch (e) {
if (e instanceof Error && /Unhandled attribute/.test(e.message)) {
logger.warn(e.message);
return result; // ignore unknown attribute, keep text
}
throw e;
} Prevention
- Make the default case return result unchanged rather than throw for inline attributes.
- Pin a BBC API response fixture so new attributes are caught by CI.
- Log unknown attributes so the route can be extended promptly.
When it happens
Trigger: The BBC content API returns an attribute string that is not 'bold' or 'italic' inside a block's attributes array - BBC added a new inline formatting attribute.
Common situations: BBC rolls out underline/strikethrough/link styling on a new article; an old article migrated with a legacy attribute value; a regional BBC endpoint returning an extended attribute set.
Related errors
- 无法在 HTML 缓存中提取核心数据对象
- 文章列表不存在或为空
- wechat-mp: ${params.join(': ')} Consider raise an issue (men
- wechat-mp: ${params.join(': ')}
- Unable to find s-data in page
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/191ccbaf9ca54310.
Report an issue: GitHub.