{"record":{"id":"f010475027c195eb","repo":"siyuan-note/siyuan","slug":"directory-not-found-s","errorCode":null,"errorMessage":"directory not found: %s","messagePattern":"directory not found: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","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/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/root.go#L69-L105","documentation":"Thrown in `rootCmd.PersistentPreRunE` when the resolved workspace path does not exist on disk. The workspace is resolved from `--workspace` flag, else `SIYUAN_WORKSPACE_PATH` env var, else `~/SiYuan`. `os.Stat` reports IsNotExist, so the directory was never created or was deleted. The check precedes `util.InitWorkspace`, which would fail deeper without this clear message.","triggerScenarios":"First run on a machine where `~/SiYuan` was never created; `--workspace /nonexistent`; `SIYUUAN_WORKSPACE_PATH` (typo) pointing nowhere; the workspace directory was moved or deleted out from under the CLI.","commonSituations":"Fresh install where the GUI app (which creates `~/SiYuan`) has never been launched; CI/containers that set `SIYUAN_WORKSPACE_PATH` to an unmounted or un-created volume; migrating to a new machine and forgetting to copy the workspace.","solutions":["Launch the SiYuan GUI app once to create `~/SiYuan`, then retry the CLI.","Point to an existing workspace explicitly: `--workspace /path/to/SiYuan`.","Set `SIYUAN_WORKSPACE_PATH` correctly (check spelling) and ensure the directory is mounted.","Create the directory first if you intend a new workspace, then let the kernel initialize it: `mkdir -p /path/to/ws`."],"exampleFix":"// before\nsiyuan --workspace /mnt/missing search foo\n// after\nmkdir -p /mnt/siyuan && siyuan --workspace /mnt/siyuan search foo","handlingStrategy":"validation","validationCode":"// Resolve and verify workspace before invoking the kernel CLI.\nws := workspacePath\nif ws == \"\" {\n    ws = os.Getenv(\"SIYUAN_WORKSPACE_PATH\")\n}\nif ws == \"\" {\n    ws = filepath.Join(homeDir, \"SiYuan\")\n}\nif fi, err := os.Stat(ws); err != nil || !fi.IsDir() {\n    log.Fatalf(\"workspace not found: %s — create it or pass --workspace\", ws)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Launch the GUI app once to create `~/SiYuan` before using the CLI.","Always pass `--workspace` explicitly in automation.","Double-check the spelling of `SIYUAN_WORKSPACE_PATH`.","Ensure mounted volumes exist before pointing the workspace at them."],"tags":["cli","bootstrap","workspace","filesystem","environment"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}