{"record":{"id":"0861d06e032a37e0","repo":"siyuan-note/siyuan","slug":"marshal-workspace-conf-s-failed-s","errorCode":null,"errorMessage":"marshal workspace conf [%s] failed: %s","messagePattern":"marshal workspace conf \\[(.+?)\\] failed: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/working.go","lineNumber":459,"sourceCode":"\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)\n\t\t}\n\t}\n\tret = tmp\n\tret = DeduplicateWorkspacePaths(ret)\n\treturn\n}\n\nfunc WriteWorkspacePaths(workspacePaths []string) (err error) {\n\tworkspacePaths = DeduplicateWorkspacePaths(workspacePaths)\n\tworkspaceConf := filepath.Join(HomeDir, \".config\", \"siyuan\", \"workspace.json\")\n\tdata, err := gulu.JSON.MarshalJSON(workspacePaths)\n\tif err != nil {\n\t\tmsg := fmt.Sprintf(\"marshal 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 = filelock.WriteFile(workspaceConf, data); err != nil {\n\t\tmsg := fmt.Sprintf(\"write workspace conf [%s] failed: %s\", workspaceConf, err)\n\t\tlogging.LogError(msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\treturn\n}\n\nvar (\n\tServerURL  *url.URL // 内核服务 URL\n\tServerPort = \"0\"    // HTTP/WebSocket 端口，0 为使用随机端口\n\n\tReadOnly       bool\n\tAccessAuthCode string","sourceCodeStart":441,"sourceCodeEnd":477,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/working.go#L441-L477","documentation":"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>\".","triggerScenarios":"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.","commonSituations":"Theoretically triggered by nil or unexpected data shapes; []string marshaling virtually never fails, so encountering this suggests a defective input path or library issue.","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"],"exampleFix":"// before\ndata, err := gulu.JSON.MarshalJSON(workspacePaths)\nif err != nil {\n\tmsg := fmt.Sprintf(\"marshal workspace conf [%s] failed: %s\", workspaceConf, err)\n\terr = errors.New(msg)\n}\n// after: preserve wrap for errors.Is/As\nif err != nil {\n\terr = fmt.Errorf(\"marshal workspace conf [%s] failed: %w\", workspaceConf, err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"err := util.WriteWorkspacePaths(paths)\nif err != nil && strings.Contains(err.Error(), \"marshal workspace conf\") {\n\t// inspect input paths; marshal of []string should not fail — investigate input\n}","preventionTips":["Pass a plain []string of valid paths","Keep gulu dependency current","Treat this error as a bug indicator rather than an expected condition"],"tags":["json","config","marshal"],"backgroundTag":"json-marshal-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"}