siyuan-note/siyuan · error

write pandoc docx filter

Error message

write pandoc docx filter: %w

What it means

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.

Solutions

  1. Check disk space and the writability of the export/temp directory used by the export
  2. Inspect the wrapped cause (%w) for the exact OS error (ENOSPC, EACCES, ENOENT)
  3. Ensure the directory passed to writePandocDocxFilter exists before calling (MkdirAll)
  4. Exclude the SiYuan temp directory from antivirus real-time scanning
  5. Fix directory permissions/ownership for the SiYuan process user

Example fix

// before
if err := os.WriteFile(filterPath, pandocDocxFilter, 0600); err != nil {
	return "", fmt.Errorf("write pandoc docx filter: %w", err)
}
// after: ensure directory exists first
if err := os.MkdirAll(dir, 0755); err != nil {
	return "", fmt.Errorf("create pandoc filter directory: %w", err)
}
if err := os.WriteFile(filterPath, pandocDocxFilter, 0600); err != nil {
	return "", fmt.Errorf("write pandoc docx filter: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// Ensure the target dir is writable first
if info, err := os.Stat(dir); err != nil || !info.IsDir() {
	os.MkdirAll(dir, 0755)
}
if f, err := os.CreateTemp(dir, "probe"); err == nil { f.Close(); os.Remove(f.Name()) }

Try / catch

filterPath, err := writePandocDocxFilter(dir)
if err != nil {
	var pathErr *os.PathError
	if errors.As(err, &pathErr) {
		log.Printf("filter write failed on %s: %v", pathErr.Path, pathErr.Err)
	}
}

Prevention

When it happens

Trigger: 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.

Common situations: Read-only export/temp directory; disk quota exceeded; Electron app sandbox restricting writes; antivirus (Defender etc.) quarantining .lua files; path length limits on Windows.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/53aca078b7436ba5. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/pandoc_docx_filter.go:34

package model

import (
	_ "embed"
	"fmt"
	"os"
	"path/filepath"
)

const pandocDocxFilterName = "siyuan-docx-filter.lua"

//go:embed pandoc_docx_filter.lua
var pandocDocxFilter []byte

func writePandocDocxFilter(dir string) (string, error) {
	filterPath := filepath.Join(dir, pandocDocxFilterName)
	if err := os.WriteFile(filterPath, pandocDocxFilter, 0600); err != nil {
		return "", fmt.Errorf("write pandoc docx filter: %w", err)
	}
	return filterPath, nil
}

func appendBuiltinPandocDocxFilter(args []string, filterPath string) []string {
	return append(args, "--lua-filter", filterPath)
}

View on GitHub (pinned to 9f775e8a12)