siyuan-note/siyuan · error

write workspace conf

Error message

write workspace conf [%s] failed: %s

What it means

I/O failure report in WriteWorkspacePaths: filelock.WriteFile could not persist the workspace path list to ~/.config/siyuan/workspace.json. This fires on disk errors such as missing directory, permission denial, or a locked file while saving multi-window workspace configuration; callers include Close, initWorkspaceDir, and the mobile variant.

Solutions

  1. Check write permissions on <HomeDir>/.config/siyuan and ensure the directory exists
  2. Free disk space if the volume is full
  3. Close other running SiYuan instances that may hold the file lock
  4. Check the wrapped error for permission-denied vs read-only-filesystem specifics and remount/chown accordingly

Example fix

// ensure the config directory exists before writing
if err := os.MkdirAll(filepath.Dir(workspaceConf), 0755); err != nil {
	return err
}
if err = filelock.WriteFile(workspaceConf, data); err != nil {
	return fmt.Errorf("write workspace conf [%s] failed: %w", workspaceConf, err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure directory is writable beforehand
info, err := os.Stat(confDir)
if err != nil || !info.IsDir() { os.MkdirAll(confDir, 0755) }
if unix.Access(confDir, unix.W_OK) != nil { /* surface permission problem early */ }

Try / catch

err := util.WriteWorkspacePaths(paths)
if err != nil && strings.Contains(err.Error(), "write workspace conf") {
	// check disk space, permissions, and competing instances before retrying
}

Prevention

When it happens

Trigger: The .config/siyuan directory is missing or read-only, disk is full, another SiYuan instance holds a conflicting file lock, or the filesystem denies writes (permissions, read-only mount).

Common situations: Read-only home directory or sandboxed app containers, full disk, config directory owned by another user, multiple kernel instances racing on the same workspace config.

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/8d852179141dd2fc. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/working.go:466

	ret = DeduplicateWorkspacePaths(ret)
	return
}

func WriteWorkspacePaths(workspacePaths []string) (err error) {
	workspacePaths = DeduplicateWorkspacePaths(workspacePaths)
	workspaceConf := filepath.Join(HomeDir, ".config", "siyuan", "workspace.json")
	data, err := gulu.JSON.MarshalJSON(workspacePaths)
	if err != nil {
		msg := fmt.Sprintf("marshal workspace conf [%s] failed: %s", workspaceConf, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

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

var (
	ServerURL  *url.URL // 内核服务 URL
	ServerPort = "0"    // HTTP/WebSocket 端口,0 为使用随机端口

	ReadOnly       bool
	AccessAuthCode string
	Lang           = ""

	Container        string // docker, android, ios, harmony, std
	ISMicrosoftStore bool   // 桌面端是否是微软商店版
)

const (

View on GitHub (pinned to 9f775e8a12)