{"record":{"id":"0f8485e1dcd173e2","repo":"siyuan-note/siyuan","slug":"not-a-valid-workspace-s","errorCode":null,"errorMessage":"not a valid workspace: %s","messagePattern":"not a valid workspace: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/root.go","lineNumber":90,"sourceCode":"\n\t\tlangsDir := filepath.Join(util.WorkingDir, \"appearance\", \"langs\")\n\t\tif _, err := os.Stat(langsDir); os.IsNotExist(err) {\n\t\t\treturn fmt.Errorf(\"appearance files not found at [%s]\", langsDir)\n\t\t}\n\n\t\t// 设置工作空间路径\n\t\tif workspacePath == \"\" {\n\t\t\tworkspacePath = os.Getenv(\"SIYUAN_WORKSPACE_PATH\")\n\t\t}\n\t\tif workspacePath == \"\" {\n\t\t\tworkspacePath = filepath.Join(util.HomeDir, \"SiYuan\")\n\t\t}\n\n\t\tif _, err := os.Stat(workspacePath); os.IsNotExist(err) {\n\t\t\treturn fmt.Errorf(\"directory not found: %s\", workspacePath)\n\t\t}\n\t\tif !util.IsWorkspaceDir(workspacePath) {\n\t\t\treturn fmt.Errorf(\"not a valid workspace: %s\", workspacePath)\n\t\t}\n\n\t\tutil.Mode = \"prod\"\n\t\tutil.InitWorkspace(workspacePath, util.WorkingDir)\n\n\t\tlogging.SetLogPath(filepath.Join(util.TempDir, \"siyuan-cli.log\"))\n\t\tlogging.SetLogToStdout(false)\n\n\t\t// CLI 单次命令默认 warn 级别（siyuan-cli.log 只保留警告及以上），避免内核初始化的大量 Info/Debug 日志噪声；\n\t\t// 用户可通过 --log-level 显式覆盖。把级别记入 util.CLILogLevel，使随后的 model.InitConf 不再用 conf.json 覆盖。\n\t\t// 注意 serve 子命令走自己的 PersistentPreRunE，不受此默认值影响，仍跟随 conf.json 的 system.logLevel。\n\t\teffectiveLevel := logLevel\n\t\tif \"\" == effectiveLevel {\n\t\t\teffectiveLevel = \"warn\"\n\t\t}\n\t\tlogging.SetLogLevel(effectiveLevel)\n\t\tutil.CLILogLevel = effectiveLevel\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/root.go#L72-L108","documentation":"The workspace directory exists but fails util.IsWorkspaceDir's structural check, so the CLI refuses to initialize it. A valid SiYuan workspace must contain its marker subdirectories/files (e.g. the conf/data layout SiYuan creates); this prevents pointing the kernel at an arbitrary or foreign directory and mutating unrelated data.","triggerScenarios":"Passing -w or SIYUAN_WORKSPACE_PATH pointing at an existing directory that is not a SiYuan workspace — e.g. an empty folder, a directory containing only notebooks without workspace metadata, or a path that once was a workspace but lost its marker entries.","commonSituations":"Typo so -w lands on the parent or sibling of the real workspace; pointing at a folder created manually with just docs; pointing at a data/ subfolder instead of the workspace root; partially deleted/restored workspaces missing their marker files.","solutions":["Point -w (or SIYUAN_WORKSPACE_PATH) at the actual workspace root — the directory SiYuan created (it contains conf/, data/, etc.), not a parent or a data subfolder.","Open the intended directory once in the SiYuan app so it is properly initialized as a workspace, then rerun the CLI.","List the directory contents and confirm the workspace structure; correct the path if you accidentally targeted an empty or unrelated folder."],"exampleFix":"// before: pointing at parent\nSiYuan-Kernel search -w ~/Documents\n// after: pointing at the workspace root\nSiYuan-Kernel search -w ~/SiYuan","handlingStrategy":"validation","validationCode":"# Shell: confirm the directory looks like a SiYuan workspace\n[ -d \"$WS/conf\" ] && [ -d \"$WS/data\" ] || { echo \"not a SiYuan workspace: $WS\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := runKernelCLI(args); err != nil && strings.HasPrefix(err.Error(), \"not a valid workspace\") {\n    // open the directory in the SiYuan app once to initialize it, then retry\n}","preventionTips":["Always point -w at the workspace root created by the SiYuan app, never at parents or the data/ subfolder.","Initialize new workspaces through the app before using them with the CLI.","Keep one canonical workspace path in your scripts to avoid typos."],"tags":["cli","workspace","validation"],"backgroundTag":"invalid-config-value","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"}