{"record":{"id":"f010475027c195eb","repo":"siyuan-note/siyuan","slug":"directory-not-found-s","errorCode":null,"errorMessage":"directory not found: %s","messagePattern":"directory not found: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/root.go","lineNumber":87,"sourceCode":"\t\tif workingDir := resolveWorkingDir(); workingDir != \"\" {\n\t\t\tutil.WorkingDir = workingDir\n\t\t}\n\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}","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/root.go#L69-L105","documentation":"After resolving the workspace path (in order: --workspace/-w flag, SIYUAN_WORKSPACE_PATH env var, then ~/SiYuan default), the CLI stats the directory before initializing it. If the path does not exist on disk, the command aborts with this error. The CLI requires an existing workspace; it never creates one implicitly.","triggerScenarios":"Running e.g. `SiYuan-Kernel search ... -w /path/to/ws` or with SIYUAN_WORKSPACE_PATH set to a path that does not exist, and no -w flag override. Also occurs when the default ~/SiYuan was never created (fresh machine) and any non-workspace subcommand is run.","commonSituations":"Typo in the -w value or in SIYUAN_WORKSPACE_PATH; pointing at a workspace deleted or moved after a sync/migration; running the CLI on a machine where SiYuan has never been launched (no ~/SiYuan); Windows/macOS path-case mismatches; container mounts missing the volume.","solutions":["Create the workspace first by launching the SiYuan app once, or pass -w pointing at an existing workspace directory.","Check the SIYUAN_WORKSPACE_PATH environment variable value and correct or unset it if it points to a stale path.","Verify the exact spelling/case of the path (`ls <path>`); fix the -w argument accordingly.","If the workspace was moved, update the -w flag or env var to the new location."],"exampleFix":"// before\nexport SIYUAN_WORKSPACE_PATH=/Users/me/Documents/SiYuan-old\nSiYuan-Kernel search -m 4\n// after\nexport SIYUAN_WORKSPACE_PATH=/Users/me/SiYuan   # existing directory\nSiYuan-Kernel search -m 4","handlingStrategy":"validation","validationCode":"# Shell: verify workspace exists before calling the CLI\nif [ ! -d \"$SIYUAN_WORKSPACE_PATH\" ]; then echo \"workspace missing: $SIYUAN_WORKSPACE_PATH\"; exit 1; fi","typeGuard":null,"tryCatchPattern":"if err := runKernelCLI(args); err != nil && strings.HasPrefix(err.Error(), \"directory not found\") {\n    // create/initialize workspace (launch the app once) or fix -w before retry\n}","preventionTips":["Store the workspace path in one scripted variable and validate it with a stat before every CLI invocation.","Avoid relying on the ~/SiYuan default in automation; always pass an explicit -w.","After moving or syncing a workspace, re-check the path before running CLI commands."],"tags":["cli","workspace","path"],"backgroundTag":"directory-not-found","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"}