siyuan-note/siyuan · error

write data [%s] failed: %s

Error message

write data [%s] failed: %s

What it means

Returned by `writeTreeByWriteFile` when `filelock.WriteFile(filePath, data)` fails. The underlying error is wrapped into a descriptive message that includes the file path and the original error, then logged via `logging.LogErrorf` before being returned. This is the I/O failure path for persisting a `.sy` tree to disk.

Source

Thrown at kernel/filesys/tree.go:440

		}
	}

	if util.ExceedLargeFileWarningSize(len(data)) {
		msg := fmt.Sprintf(util.Langs[util.Lang][268], tree.Root.IALAttr("title")+" "+filepath.Base(filePath), util.LargeFileWarningSize)
		util.PushErrMsg(msg, 7000)
	}

	cache.SetTreeDataInBox(tree.ID, tree.Box, data)
	afterWriteTree(tree)
	size = uint64(len(data))
	return
}

func writeTreeByWriteFile(filePath string, data []byte) (err error) {
	if err = filelock.WriteFile(filePath, data); err != nil {
		msg := fmt.Sprintf("write data [%s] failed: %s", filePath, err)
		logging.LogErrorf("%s", msg)
		err = errors.New(msg)
		return
	}
	return
}

func prepareWriteTree(tree *parse.Tree) (data []byte, filePath string, err error) {
	luteEngine := util.NewLute() // 不关注用户的自定义解析渲染选项

	if nil == tree.Root.FirstChild {
		newP := treenode.NewParagraph("")
		tree.Root.AppendChild(newP)
		tree.Root.SetIALAttr("updated", util.TimeFromID(newP.ID))
		treenode.UpsertBlockTree(tree)
	}

	treenode.UpgradeSpec(tree)

	if _, err = ValidateBoxRelativePath(tree.Box, tree.Path); err != nil {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Free disk space and retry the write.
  2. Check filesystem permissions on `data/` and the target box directory.
  3. Inspect the wrapped error in the log for the specific OS error (ENOENT, EACCES, etc.) and address it.
  4. If a stale lock is suspected, ensure no other SiYuan kernel is running against the same workspace.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check writability when possible:
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
    return err
}

Try / catch

if err := filesys.WriteTree(tree); err != nil {
    if strings.Contains(err.Error(), "write data") {
        // surface the wrapped OS error to the user; offer retry/history restore
    }
    return err
}

Prevention

When it happens

Trigger: Disk full, permission denied, read-only filesystem, file locked by another process, or the parent directory removed mid-write. Any error from `filelock.WriteFile` is funneled into this message.

Common situations: Synchronizing to a full disk; antivirus/filelock contention on Windows; running on a read-only mount; path to a directory that no longer exists after a move.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/034aab3e306ae38d. Report an issue: GitHub.