{"record":{"id":"7a30d1038362de89","repo":"siyuan-note/siyuan","slug":"export-failed-empty-artifact-path","errorCode":null,"errorMessage":"export failed: empty artifact path","messagePattern":"export failed: empty artifact path","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/export.go","lineNumber":223,"sourceCode":"\n\t\tzipPath, err := model.ExportData()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tresultPath, err := materializeExportArtifact(zipPath, output)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif output == \"\" {\n\t\t\tfmt.Println(resultPath)\n\t\t}\n\t\treturn nil\n\t},\n}\n\nfunc materializeExportArtifact(exportPath, output string) (resultPath string, err error) {\n\tif exportPath == \"\" {\n\t\treturn \"\", fmt.Errorf(\"export failed: empty artifact path\")\n\t}\n\tlease, err := model.AcquireExportArtifactLease(exportPath)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer model.ReleaseExportArtifactLease(lease.ID)\n\n\tif output == \"\" {\n\t\treturn lease.Path, nil\n\t}\n\tif err = filelock.Copy(lease.Path, output); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn output, nil\n}\n\nfunc init() {\n\texportMdCmd.Flags().String(\"id\", \"\", \"block ID\")","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/export.go#L205-L241","documentation":"materializeExportArtifact is the post-export step that takes the artifact path produced by the kernel export routine and secures it via an export-artifact lease before copying it to the requested output. If the export path comes back empty it means the underlying export produced no file, so it returns this error instead of leasing a nonexistent path.","triggerScenarios":"The kernel export call (model export for html/preview/docx/sy/md-zip) returns success but with an empty exportPath — e.g. the document failed to render or the export API silently produced nothing — and materializeExportArtifact is then invoked with exportPath=\"\".","commonSituations":"Exporting a document whose tree is missing/corrupted in the workspace; calling this helper from tests with an empty path (see TestMaterializeExportArtifactRejectsEmptyPath); a kernel API change that stopped returning the artifact path.","solutions":["Check that the document ID exists in the workspace and its .sy file is readable before exporting.","Log/inspect the return value of the underlying model export call; fix the upstream export to return a real path.","If this is a test, pass a non-empty fixture path (the empty-path rejection is intentional).","Retry after restarting the kernel / re-indexing if the export subsystem returned empty due to transient state."],"exampleFix":"// before\npath, _ := model.ExportDocHTML(id)\nresult, err := materializeExportArtifact(path, output) // panics into empty-path error\n\n// after\npath, err := model.ExportDocHTML(id)\nif err != nil {\n    return err\n}\nif path == \"\" {\n    return fmt.Errorf(\"export produced no artifact for id %s\", id)\n}\nresult, err := materializeExportArtifact(path, output)","handlingStrategy":"try-catch","validationCode":"path, err := model.ExportDocHTML(id)\nif err != nil {\n    return fmt.Errorf(\"upstream export for %s failed: %w\", id, err)\n}\nif path == \"\" {\n    return fmt.Errorf(\"export for %s produced no artifact\", id)\n}\nreturn materializeExportArtifact(path, output)","typeGuard":null,"tryCatchPattern":"result, err := materializeExportArtifact(path, output)\nif err != nil {\n    if strings.Contains(err.Error(), \"empty artifact path\") {\n        // upstream export returned no path; re-export or report id\n    }\n    return err\n}","preventionTips":["Never discard the error from the underlying export call","Assert non-empty artifact path before leasing","Verify the document exists in the workspace before exporting","Keep tests using intentional empty-path cases only for the rejection path"],"tags":["export","cli","empty-path"],"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"}