{"record":{"id":"53aca078b7436ba5","repo":"siyuan-note/siyuan","slug":"write-pandoc-docx-filter-w","errorCode":null,"errorMessage":"write pandoc docx filter: %w","messagePattern":"write pandoc docx filter: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/pandoc_docx_filter.go","lineNumber":34,"sourceCode":"\npackage model\n\nimport (\n\t_ \"embed\"\n\t\"fmt\"\n\t\"os\"\n\t\"path/filepath\"\n)\n\nconst pandocDocxFilterName = \"siyuan-docx-filter.lua\"\n\n//go:embed pandoc_docx_filter.lua\nvar pandocDocxFilter []byte\n\nfunc writePandocDocxFilter(dir string) (string, error) {\n\tfilterPath := filepath.Join(dir, pandocDocxFilterName)\n\tif err := os.WriteFile(filterPath, pandocDocxFilter, 0600); err != nil {\n\t\treturn \"\", fmt.Errorf(\"write pandoc docx filter: %w\", err)\n\t}\n\treturn filterPath, nil\n}\n\nfunc appendBuiltinPandocDocxFilter(args []string, filterPath string) []string {\n\treturn append(args, \"--lua-filter\", filterPath)\n}\n","sourceCodeStart":16,"sourceCodeEnd":42,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/pandoc_docx_filter.go#L16-L42","documentation":"writePandocDocxFilter writes the embedded pandoc_docx_filter.lua (go:embed) to a working directory and wraps any os.WriteFile failure as \"write pandoc docx filter: %w\". Export to DOCX via pandoc needs this Lua filter on disk; without it the export cannot proceed.","triggerScenarios":"DOCX export preparing the pandoc command line: os.WriteFile fails because the target directory does not exist or is not writable, the disk is full, antivirus locks the file, or the temp/export directory has wrong permissions.","commonSituations":"Read-only export/temp directory; disk quota exceeded; Electron app sandbox restricting writes; antivirus (Defender etc.) quarantining .lua files; path length limits on Windows.","solutions":["Check disk space and the writability of the export/temp directory used by the export","Inspect the wrapped cause (%w) for the exact OS error (ENOSPC, EACCES, ENOENT)","Ensure the directory passed to writePandocDocxFilter exists before calling (MkdirAll)","Exclude the SiYuan temp directory from antivirus real-time scanning","Fix directory permissions/ownership for the SiYuan process user"],"exampleFix":"// before\nif err := os.WriteFile(filterPath, pandocDocxFilter, 0600); err != nil {\n\treturn \"\", fmt.Errorf(\"write pandoc docx filter: %w\", err)\n}\n// after: ensure directory exists first\nif err := os.MkdirAll(dir, 0755); err != nil {\n\treturn \"\", fmt.Errorf(\"create pandoc filter directory: %w\", err)\n}\nif err := os.WriteFile(filterPath, pandocDocxFilter, 0600); err != nil {\n\treturn \"\", fmt.Errorf(\"write pandoc docx filter: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// Ensure the target dir is writable first\nif info, err := os.Stat(dir); err != nil || !info.IsDir() {\n\tos.MkdirAll(dir, 0755)\n}\nif f, err := os.CreateTemp(dir, \"probe\"); err == nil { f.Close(); os.Remove(f.Name()) }","typeGuard":null,"tryCatchPattern":"filterPath, err := writePandocDocxFilter(dir)\nif err != nil {\n\tvar pathErr *os.PathError\n\tif errors.As(err, &pathErr) {\n\t\tlog.Printf(\"filter write failed on %s: %v\", pathErr.Path, pathErr.Err)\n\t}\n}","preventionTips":["Keep adequate free disk space for exports","Exclude the app temp dir from antivirus scanning","Ensure export/temp directories exist and are writable by the app user","Avoid read-only mounts for directories used during export"],"tags":["go","file-io","export","pandoc"],"backgroundTag":"file-write-failed","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"}