siyuan-note/siyuan · error
marshal workspace conf
Error message
marshal workspace conf [%s] failed: %s
What it means
WriteWorkspacePaths serializes the deduplicated workspace path list to JSON with gulu.JSON.MarshalJSON before writing workspace.json. A marshaling failure produces "marshal workspace conf [<path>] failed: <err>".
Solutions
- Verify workspacePaths is a plain []string of valid paths before calling WriteWorkspacePaths
- Check the wrapped error message for the actual marshal cause
- Upgrade gulu to the current version used by the kernel
- If reproducible, report with the exact workspacePaths value
Example fix
// before
data, err := gulu.JSON.MarshalJSON(workspacePaths)
if err != nil {
msg := fmt.Sprintf("marshal workspace conf [%s] failed: %s", workspaceConf, err)
err = errors.New(msg)
}
// after: preserve wrap for errors.Is/As
if err != nil {
err = fmt.Errorf("marshal workspace conf [%s] failed: %w", workspaceConf, err)
} Defensive patterns
Strategy: try-catch
Try / catch
err := util.WriteWorkspacePaths(paths)
if err != nil && strings.Contains(err.Error(), "marshal workspace conf") {
// inspect input paths; marshal of []string should not fail — investigate input
} Prevention
- Pass a plain []string of valid paths
- Keep gulu dependency current
- Treat this error as a bug indicator rather than an expected condition
When it happens
Trigger: gulu.JSON.MarshalJSON fails on the []string; in practice this is rare and points to a corrupted/unsupported state of workspacePaths or a marshaling bug.
Common situations: Theoretically triggered by nil or unexpected data shapes; []string marshaling virtually never fails, so encountering this suggests a defective input path or library issue.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- builtin color must not be null
- builtin style must not be null
- failed to serialize config.
- invalid config.
- map[string]apicontract.JSONValue
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/0861d06e032a37e0.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/working.go:459
if gulu.File.IsDir(d) {
tmp = append(tmp, d)
} else {
logging.LogWarnf("workspace path [%s] is not a dir", d)
}
}
ret = tmp
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 stringView on GitHub (pinned to 9f775e8a12)