siyuan-note/siyuan · error
write workspace conf [%s] failed: %s
Error message
write workspace conf [%s] failed: %s
What it means
After successfully marshaling the workspace-paths list, WriteWorkspacePaths writes the bytes to ~/.config/siyuan/workspace.json through filelock.WriteFile. This error means that locked file write failed (disk, permissions, lock contention, or path problems). The write is what registers/unregisters workspace directories in the launcher UI.
Source
Thrown at kernel/util/working.go:463
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 8641553a1f)
Solutions
- Check kernel log for the underlying write error wrapped in the message
- Verify ~/.config/siyuan/workspace.json is writable by the running user (ls -l, chown if it was created by root)
- Free disk space / confirm the home filesystem is not mounted read-only
- Close other SiYuan instances or processes locking the file, then retry
- If irrecoverable, back up and remove workspace.json; it is regenerated on next workspace open
Example fix
// before: repeated 'write workspace conf failed' as root-created file sudo chown -R $(whoami) ~/.config/siyuan // after: file writable, workspace list persists normally
Defensive patterns
Strategy: validation
Validate before calling
// Go: check the config file is writable before triggering workspace ops
conf := filepath.Join(os.Getenv("HOME"), ".config", "siyuan", "workspace.json")
if f, err := os.OpenFile(conf, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
return fmt.Errorf("workspace.json not writable: %w", err)
} else { f.Close() } Try / catch
// Go
if err := util.WriteWorkspacePaths(paths); err != nil {
if strings.Contains(err.Error(), "write workspace conf") {
// surface a user-facing hint about ~/.config/siyuan permissions/disk space
return err
}
return err
} Prevention
- Never run SiYuan with sudo for the first launch - it creates root-owned files in ~/.config/siyuan
- Keep a few hundred MB free on the home filesystem
- Exclude ~/.config/siyuan from antivirus/backup lock contention
- Check file ownership after OS/user migrations
When it happens
Trigger: Any caller of WriteWorkspacePaths (setWorkspaceDir, createWorkspaceDir, removeWorkspaceDir, removeWorkspaceDirPhysically, Close) when filelock.WriteFile cannot write ~/.config/siyuan/workspace.json.
Common situations: Read-only or full home directory; ~/.config/siyuan owned by another user (ran once as root/sudo); antivirus or backup tool holding the file; disk full; corrupted file lock state.
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
- write inline styles failed: %w
- write file failed:
- install local marketplace package failed: %w; rollback faile
- read session file failed: %w
- create session dir failed: %w
AI-assisted analysis of siyuan-note/siyuan@8641553a1f (2026-09-11).
Data as JSON: /api/errors/8d852179141dd2fc.
Report an issue: GitHub.