{"record":{"id":"6de83bd9917622a0","repo":"siyuan-note/siyuan","slug":"unmarshal-workspace-conf-s-failed-s","errorCode":null,"errorMessage":"unmarshal workspace conf [%s] failed: %s","messagePattern":"unmarshal workspace conf \\[(.+?)\\] failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/working.go","lineNumber":426,"sourceCode":"\t}\n\treturn result\n}\n\nfunc ReadWorkspacePaths() (ret []string, err error) {\n\tret = []string{}\n\tworkspaceConf := filepath.Join(HomeDir, \".config\", \"siyuan\", \"workspace.json\")\n\tdata, err := os.ReadFile(workspaceConf)\n\tif err != nil {\n\t\tmsg := fmt.Sprintf(\"read workspace conf [%s] failed: %s\", workspaceConf, err)\n\t\tlogging.LogError(msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\n\tif err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {\n\t\tmsg := fmt.Sprintf(\"unmarshal workspace conf [%s] failed: %s\", workspaceConf, err)\n\t\tlogging.LogError(msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\n\tvar tmp []string\n\tworkspaceBaseDir := filepath.Dir(HomeDir)\n\tfor _, d := range ret {\n\t\tif ContainerIOS == Container && strings.Contains(d, \"/Documents/\") {\n\t\t\t// iOS 端沙箱路径会变化，需要转换为相对路径再拼接当前沙箱中的工作空间基路径\n\t\t\td = d[strings.Index(d, \"/Documents/\")+len(\"/Documents/\"):]\n\t\t\td = filepath.Join(workspaceBaseDir, d)\n\t\t}\n\n\t\td = strings.TrimRight(d, \" \\t\\n\") // 去掉工作空间路径尾部空格 https://github.com/siyuan-note/siyuan/issues/6353\n\t\td = filepath.Clean(d)             // 归一化路径分隔符，清理历史持久化的斜杠差异（如 D:/foo 与 D:\\foo） https://github.com/siyuan-note/siyuan/issues/17862\n\t\tif gulu.File.IsDir(d) {\n\t\t\ttmp = append(tmp, d)\n\t\t} else {\n\t\t\tlogging.LogWarnf(\"workspace path [%s] is not a dir\", d)","sourceCodeStart":408,"sourceCodeEnd":444,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working.go#L408-L444","documentation":"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>\".","triggerScenarios":"workspace.json contains invalid JSON (truncated write, manual edit), a JSON object instead of an array, or non-string elements in the array.","commonSituations":"Hand-edited config files, crash during a previous write leaving partial content, another tool rewriting the file in a different schema, encoding issues.","solutions":["Open workspace.json and fix or regenerate it as a valid JSON array of path strings, e.g. [\"/path/to/ws\"]","Validate the JSON with a linter/parser before saving","If the file is corrupt, back it up and recreate with an empty array []","Ensure writes go through WriteWorkspacePaths so the file stays valid"],"exampleFix":"// corrupt file\n{\"workspace\": \"/home/u/SiYuan\"}\n// valid format\n[\"/home/u/SiYuan\"]","handlingStrategy":"validation","validationCode":"// validate workspace.json parses as []string before the kernel reads it\nvar v []string\ndata, _ := os.ReadFile(confPath)\nif err := json.Unmarshal(data, &v); err != nil {\n\t// repair or reset the file to []\n}","typeGuard":null,"tryCatchPattern":"paths, err := util.ReadWorkspacePaths()\nif err != nil && strings.Contains(err.Error(), \"unmarshal workspace conf\") {\n\t// back up the corrupt file and recreate as []\n}","preventionTips":["Edit workspace.json only while the kernel is closed","Always save as a JSON array of strings","Validate JSON after manual edits","Let the app own the file instead of external tooling"],"tags":["json","config","unmarshal"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}