siyuan-note/siyuan · error

unmarshal workspace conf

Error message

unmarshal workspace conf [%s] failed: %s

What it means

After reading workspace.json, ReadWorkspacePaths unmarshals it as a JSON string array via gulu.JSON.UnmarshalJSON. Malformed or non-array JSON yields "unmarshal workspace conf [<path>] failed: <err>".

Solutions

  1. Open workspace.json and fix or regenerate it as a valid JSON array of path strings, e.g. ["/path/to/ws"]
  2. Validate the JSON with a linter/parser before saving
  3. If the file is corrupt, back it up and recreate with an empty array []
  4. Ensure writes go through WriteWorkspacePaths so the file stays valid

Example fix

// corrupt file
{"workspace": "/home/u/SiYuan"}
// valid format
["/home/u/SiYuan"]
Defensive patterns

Strategy: validation

Validate before calling

// validate workspace.json parses as []string before the kernel reads it
var v []string
data, _ := os.ReadFile(confPath)
if err := json.Unmarshal(data, &v); err != nil {
	// repair or reset the file to []
}

Try / catch

paths, err := util.ReadWorkspacePaths()
if err != nil && strings.Contains(err.Error(), "unmarshal workspace conf") {
	// back up the corrupt file and recreate as []
}

Prevention

When it happens

Trigger: workspace.json contains invalid JSON (truncated write, manual edit), a JSON object instead of an array, or non-string elements in the array.

Common situations: Hand-edited config files, crash during a previous write leaving partial content, another tool rewriting the file in a different schema, encoding issues.

Understand the failure class

Background: "failed to unmarshal" / json.Unmarshal errors: why parsing a response into a Go struct fails and how to fix it — this error's family across 23 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/6de83bd9917622a0. Report an issue: GitHub.

Appendix: source

Thrown at kernel/util/working.go:426

	}
	return result
}

func ReadWorkspacePaths() (ret []string, err error) {
	ret = []string{}
	workspaceConf := filepath.Join(HomeDir, ".config", "siyuan", "workspace.json")
	data, err := os.ReadFile(workspaceConf)
	if err != nil {
		msg := fmt.Sprintf("read workspace conf [%s] failed: %s", workspaceConf, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

	if err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {
		msg := fmt.Sprintf("unmarshal workspace conf [%s] failed: %s", workspaceConf, err)
		logging.LogError(msg)
		err = errors.New(msg)
		return
	}

	var tmp []string
	workspaceBaseDir := filepath.Dir(HomeDir)
	for _, d := range ret {
		if ContainerIOS == Container && strings.Contains(d, "/Documents/") {
			// iOS 端沙箱路径会变化,需要转换为相对路径再拼接当前沙箱中的工作空间基路径
			d = d[strings.Index(d, "/Documents/")+len("/Documents/"):]
			d = filepath.Join(workspaceBaseDir, d)
		}

		d = strings.TrimRight(d, " \t\n") // 去掉工作空间路径尾部空格 https://github.com/siyuan-note/siyuan/issues/6353
		d = filepath.Clean(d)             // 归一化路径分隔符,清理历史持久化的斜杠差异(如 D:/foo 与 D:\foo) https://github.com/siyuan-note/siyuan/issues/17862
		if gulu.File.IsDir(d) {
			tmp = append(tmp, d)
		} else {
			logging.LogWarnf("workspace path [%s] is not a dir", d)

View on GitHub (pinned to 9f775e8a12)