siyuan-note/siyuan · error · Error
export custom font failed
Error message
export custom font failed: ${response.status} What it means
getExportCustomFontStyle fetches each matching custom font binary from /custom-fonts/<id> and throws this Error when the HTTP response is not ok (fetch only rejects on network failure, not on HTTP error statuses). It reports the status code so the caller knows whether the font file was missing (404), forbidden (403), or the server errored (5xx).
Solutions
- Check that the font file exists under the workspace custom-fonts directory and re-upload it in settings - appearance
- Verify the font.id in the custom fonts config matches a served asset (curl /custom-fonts/<id>)
- Wrap the export call in try/catch and fall back to rendering without the custom font
- Re-register the font (remove and re-add) to regenerate its ID mapping
Example fix
// before
const styles = await getExportCustomFontStyle(families);
// after
let styles = "";
try {
styles = await getExportCustomFontStyle(families);
} catch (e) {
console.warn(e.message);
} Defensive patterns
Strategy: fallback
Validate before calling
const probe = await fetch(`/custom-fonts/${font.id}`, {method: "HEAD"});
if (!probe.ok) return ""; // skip this font in export Try / catch
try { styles = await getExportCustomFontStyle(families); } catch (e) { styles = ""; console.warn(e.message); } Prevention
- Re-register custom fonts after moving workspaces between devices
- Confirm font files exist under the workspace custom-fonts directory
- Fall back to default fonts when a font asset is missing during export
When it happens
Trigger: Calling getExportCustomFontStyle (app/src/util/customFont.ts:120) while a registered custom font's file cannot be served at /custom-fonts/<id>: font removed from disk after config still lists it, wrong font.id, or kernel serving errors during export/PDF preview.
Common situations: Exporting a document to PDF/HTML that references a custom font the kernel no longer has; fonts synced from another device without the font assets; typo'd or stale font.id in the custom-fonts config.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- asset path [ ] does not match data path [ ]
- authentication probe returned HTTP " + response.status
- boot progress request returned HTTP " + response.status
- box and dataPath cannot be used together
- catalog has no providers with API endpoints and valid models
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/db338345b07e8ee0.
Report an issue: GitHub.
Appendix: source
Thrown at app/src/util/customFont.ts:120
console.warn("load custom font failed", error);
}
};
export const ensureSelectedCustomFonts = async (fonts: Array<{ family: string; weight: number }>) => {
await Promise.all(fonts.map((font) => ensureSelectedCustomFont(font.family, font.weight)));
};
export const getExportCustomFontStyle = async (fonts: Array<{family: string}>) => {
const families = new Set(fonts.map((font) => font.family).filter((family) =>
family.startsWith(CUSTOM_FONT_FAMILY_PREFIX)));
if (window.siyuan.config.system.safeMode || families.size === 0) {
return "";
}
const customFonts = (await loadCustomFonts()).filter((font) => isValidCustomFont(font) && families.has(font.family));
const styles = await Promise.all(customFonts.map(async (font) => {
const response = await fetch(`/custom-fonts/${font.id}`);
if (!response.ok) {
throw new Error(`export custom font failed: ${response.status}`);
}
const blob = await response.blob();
const dataURL = await new Promise<string>((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result as string);
reader.onerror = () => reject(reader.error);
reader.readAsDataURL(blob);
});
return `@font-face { font-family: "${font.family}"; src: url("${dataURL}"); font-style: normal; font-weight: ${Math.max(1, Math.min(1000, font.weight || 400))}; }`;
}));
return styles.join("\n");
};
const setCustomFontStyle = (font: ICustomFont) => {
let styleElement = document.getElementById(`customFontStyle-${font.id}`) as HTMLStyleElement;
if (!styleElement) {
styleElement = document.createElement("style");
styleElement.id = `customFontStyle-${font.id}`;View on GitHub (pinned to 9f775e8a12)