{"record":{"id":"de6766df278d23c4","repo":"siyuan-note/siyuan","slug":"export-failed-empty-content","errorCode":null,"errorMessage":"export failed: empty content","messagePattern":"export failed: empty content","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/export.go","lineNumber":273,"sourceCode":"\n\texportMdZipCmd.Flags().String(\"id\", \"\", \"block ID\")\n\texportMdZipCmd.Flags().String(\"output\", \"\", \"output file path (default: print temp path)\")\n\n\texportDataCmd.Flags().String(\"output\", \"\", \"output file path (default: print temp path)\")\n\n\trootCmd.AddCommand(exportCmd)\n\texportCmd.AddCommand(exportMdCmd)\n\texportCmd.AddCommand(exportHTMLCmd)\n\texportCmd.AddCommand(exportPreviewCmd)\n\texportCmd.AddCommand(exportDocxCmd)\n\texportCmd.AddCommand(exportSYCmd)\n\texportCmd.AddCommand(exportMdZipCmd)\n\texportCmd.AddCommand(exportDataCmd)\n}\n\nfunc writeExportContent(content, output string) error {\n\tif content == \"\" {\n\t\treturn fmt.Errorf(\"export failed: empty content\")\n\t}\n\tif output != \"\" {\n\t\treturn os.WriteFile(output, []byte(content), 0644)\n\t}\n\tfmt.Print(content)\n\treturn nil\n}\n","sourceCodeStart":255,"sourceCodeEnd":281,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/export.go#L255-L281","documentation":"writeExportContent delivers the exported text content: writes it to `output` when provided, otherwise prints it to stdout. It returns this error when the exported content string is empty, since writing/echoing nothing is never a useful result and would silently clobber the output file with a zero-byte file.","triggerScenarios":"The HTML/preview/markdown export routine returned an empty string (failed render, missing document) and writeExportContent is called with content=\"\"; also invoked directly in tests with an empty string (TestWriteExportContentPreservesExistingOutputOnFailure).","commonSituations":"Exporting a document that no longer exists or renders to nothing; a pipeline where an earlier step swallowed the export result; misconfigured export options producing empty output.","solutions":["Verify the document ID is valid and the document has content before exporting.","Check the return of the underlying export call and propagate its error instead of discarding it.","Do not reuse the same output path on failure — this guard exists so an existing file is preserved; inspect rather than overwrite.","If you intentionally need to write empty content, write the file yourself with os.WriteFile instead of using this helper."],"exampleFix":"// before\ncontent, _ := renderDocHTML(id)\nerr := writeExportContent(content, out) // error: empty content\n\n// after\ncontent, err := renderDocHTML(id)\nif err != nil {\n    return err\n}\nif content == \"\" {\n    return fmt.Errorf(\"document %s rendered to empty content\", id)\n}\nreturn writeExportContent(content, out)","handlingStrategy":"validation","validationCode":"content, err := renderDocHTML(id)\nif err != nil {\n    return err\n}\nif content == \"\" {\n    return fmt.Errorf(\"empty render output for %s\", id)\n}\nreturn writeExportContent(content, output)","typeGuard":null,"tryCatchPattern":"if err := writeExportContent(content, output); err != nil {\n    if strings.Contains(err.Error(), \"empty content\") {\n        // do not overwrite output; inspect the export source first\n    }\n    return err\n}","preventionTips":["Check content for emptiness before writing to a precious output path","Propagate errors from the render/export step instead of ignoring them","Confirm the document has renderable content","Avoid reusing the same output path after a failure"],"tags":["export","cli","empty-content"],"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"}