{"record":{"id":"825872f5f09b05fd","repo":"siyuan-note/siyuan","slug":"font-file-is-empty","errorCode":null,"errorMessage":"font file is empty","messagePattern":"font file is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/custom_font.go","lineNumber":106,"sourceCode":"\nfunc LoadCustomFonts() []*CustomFont {\n\tcustomFontsLock.Lock()\n\tdefer customFontsLock.Unlock()\n\n\tloadCustomFontsLocked()\n\treturn cloneCustomFonts(customFonts)\n}\n\nfunc InstallCustomFont(tempPath string) (*CustomFont, bool, error) {\n\tcustomFontsLock.Lock()\n\tdefer customFontsLock.Unlock()\n\n\tinfo, err := os.Stat(tempPath)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\tif !info.Mode().IsRegular() || info.Size() < 1 {\n\t\treturn nil, false, errors.New(\"font file is empty\")\n\t}\n\tif MaxCustomFontSize < info.Size() {\n\t\treturn nil, false, errors.New(\"font file is too large\")\n\t}\n\n\tfontFile, err := os.Open(tempPath)\n\tif err != nil {\n\t\treturn nil, false, err\n\t}\n\n\textension, err := detectCustomFontExtension(fontFile)\n\tif err != nil {\n\t\tfontFile.Close()\n\t\treturn nil, false, err\n\t}\n\tif _, err = fontFile.Seek(0, io.SeekStart); err != nil {\n\t\tfontFile.Close()\n\t\treturn nil, false, err","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/custom_font.go#L88-L124","documentation":"InstallCustomFont validates the staged temp file before parsing it. This error is thrown when the temp path does not point to a regular file or its size is zero bytes. The library refuses to proceed because an empty file can never be a valid font.","triggerScenarios":"Calling InstallCustomFont(tempPath) where the uploaded/staged file is 0 bytes, the upload was truncated, the temp file was never written, or tempPath points at a directory or special file (info.Mode().IsRegular() fails).","commonSituations":"Frontend upload completed with an empty body; CreateCustomFontTemp created the file but writing failed silently; the temp file was discarded (DiscardCustomFontTemp or cleanup) leaving a dangling path; client passed a directory path.","solutions":["Check os.Stat(tempPath) size and mode before calling; ensure the file has bytes","Fix the upload/write step so the temp file is fully flushed and closed before installation","Regenerate the temp file via CreateCustomFontTemp and re-upload the font data","If the source font is genuinely empty/corrupt, obtain a valid font file"],"exampleFix":"// before\nfont, installed, err := util.InstallCustomFont(tempPath)\n// after\ninfo, statErr := os.Stat(tempPath)\nif statErr != nil || !info.Mode().IsRegular() || info.Size() == 0 {\n    return fmt.Errorf(\"empty or missing font upload\")\n}\nfont, installed, err := util.InstallCustomFont(tempPath)","handlingStrategy":"validation","validationCode":"info, err := os.Stat(tempPath)\nif err != nil || !info.Mode().IsRegular() || info.Size() == 0 {\n    return fmt.Errorf(\"font temp file missing or empty\")\n}","typeGuard":null,"tryCatchPattern":"font, _, err := util.InstallCustomFont(tempPath)\nif err != nil && err.Error() == \"font file is empty\" {\n    // recreate temp file and re-upload\n}","preventionTips":["Close and flush the temp file before installing","Check size > 0 after writing the upload","Discard dangling temp files via DiscardCustomFontTemp on failure"],"tags":["filesystem","validation","empty-file","custom-font"],"backgroundTag":"empty-required-field","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}