siyuan-note/siyuan · error

write publishAccess.json [%s] failed: %s

Error message

write publishAccess.json [%s] failed: %s

What it means

Thrown by SetPublishAccess() when filelock.WriteFile fails to write the serialized publishAccess.json after the directory was successfully created and data marshaled. filelock.WriteFile acquires a file lock then writes the bytes; failure indicates a low-level I/O problem at write time.

Source

Thrown at kernel/model/publish_access.go:140

	err = os.MkdirAll(filepath.Dir(publishAccessPath), 0755)
	if err != nil {
		msg := fmt.Sprintf("create dir for publishAccess.json [%s] failed: %s", publishAccessPath, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

	data, err := gulu.JSON.MarshalJSON(inputPublishAccess)
	if err != nil {
		logging.LogErrorf("marshal publishAccess.json [%s] failed: %s", publishAccessPath, err)
		return
	}

	err = filelock.WriteFile(publishAccessPath, data)
	if err != nil {
		msg := fmt.Sprintf("write publishAccess.json [%s] failed: %s", publishAccessPath, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}
	return
}

func GetInvisiblePublishAccess(inputPublishAccess PublishAccess) (outputPublishAccess PublishAccess) {
	outputPublishAccess = filterInvisiblePublishAccess(inputPublishAccess)
	outputPublishAccess = appendEncryptedBoxesToPublishAccess(outputPublishAccess)
	return
}

func filterInvisiblePublishAccess(inputPublishAccess PublishAccess) (outputPublishAccess PublishAccess) {
	outputPublishAccess = PublishAccess{}
	for _, item := range inputPublishAccess {
		if !item.Visible {
			outputPublishAccess = append(outputPublishAccess, item)
		}
	}

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Check disk space: df -h and ensure there is free space on the data volume.
  2. Ensure no other SiYuan instance is running against the same data directory (filelock contention).
  3. Check dmesg/syslog for filesystem errors that may have triggered a read-only remount.
  4. Retry the operation after freeing space or resolving the lock; if transient (AV scan, backup), it may succeed on retry.
  5. Verify write permissions are still intact on the .siyuan directory.

Example fix

# before — disk full or lock contention

# after — free space and retry
# Check: df -h
# Clear space or expand volume, then:
# The frontend 'Save' button will retry SetPublishAccess automatically.

# If lock contention from a stale process:
# ps aux | grep siyuan
# kill the stale process, then retry.
Defensive patterns

Strategy: retry

Validate before calling

// Check available disk space before writing
var stat syscall.Statfs_t
if err := syscall.Statfs(util.DataDir, &stat); err == nil {
    freeBytes := stat.Bavail * uint64(stat.Bsize)
    if freeBytes < 1024*1024 { // less than 1MB free
        return errors.New("insufficient disk space to save publish access settings")
    }
}

Try / catch

err := model.SetPublishAccess(input)
if err != nil && strings.Contains(err.Error(), "write publishAccess.json") {
    // Could be transient (disk full, lock contention) — retry once
    time.Sleep(500 * time.Millisecond)
    err = model.SetPublishAccess(input)
    if err != nil {
        log.Printf("publishAccess.json write failed after retry: %v", err)
    }
}

Prevention

When it happens

Trigger: Calling SetPublishAccess() where os.MkdirAll and gulu.JSON.MarshalJSON both succeed, but the final file write fails. Causes include: disk full during write, the file is locked by another process exclusively, permission revoked between mkdir and write, or the filesystem was remounted read-only mid-operation.

Common situations: Disk filled up between creating the directory and writing the file. Another SiYuan instance or process holds an exclusive lock on publishAccess.json. Antivirus or backup software locked the file transiently on Windows. The filesystem was remounted read-only after startup (e.g., ext4 errors triggering read-only remount).

Related errors


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