siyuan-note/siyuan · critical
directory not found: %s
Error message
directory not found: %s
What it means
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.
Source
Thrown at kernel/cli/cmd/root.go:87
if workingDir := resolveWorkingDir(); workingDir != "" {
util.WorkingDir = workingDir
}
langsDir := filepath.Join(util.WorkingDir, "appearance", "langs")
if _, err := os.Stat(langsDir); os.IsNotExist(err) {
return fmt.Errorf("appearance files not found at [%s]", langsDir)
}
// 设置工作空间路径
if workspacePath == "" {
workspacePath = os.Getenv("SIYUAN_WORKSPACE_PATH")
}
if workspacePath == "" {
workspacePath = filepath.Join(util.HomeDir, "SiYuan")
}
if _, err := os.Stat(workspacePath); os.IsNotExist(err) {
return fmt.Errorf("directory not found: %s", workspacePath)
}
if !util.IsWorkspaceDir(workspacePath) {
return fmt.Errorf("not a valid workspace: %s", workspacePath)
}
util.Mode = "prod"
util.InitWorkspace(workspacePath, util.WorkingDir)
logging.SetLogPath(filepath.Join(util.TempDir, "siyuan-cli.log"))
logging.SetLogToStdout(false)
// CLI 单次命令默认 warn 级别(siyuan-cli.log 只保留警告及以上),避免内核初始化的大量 Info/Debug 日志噪声;
// 用户可通过 --log-level 显式覆盖。把级别记入 util.CLILogLevel,使随后的 model.InitConf 不再用 conf.json 覆盖。
// 注意 serve 子命令走自己的 PersistentPreRunE,不受此默认值影响,仍跟随 conf.json 的 system.logLevel。
effectiveLevel := logLevel
if "" == effectiveLevel {
effectiveLevel = "warn"
}View on GitHub (pinned to 251596fc0d)
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`.
Example fix
// before siyuan --workspace /mnt/missing search foo // after mkdir -p /mnt/siyuan && siyuan --workspace /mnt/siyuan search foo
Defensive patterns
Strategy: validation
Validate before calling
// Resolve and verify workspace before invoking the kernel CLI.
ws := workspacePath
if ws == "" {
ws = os.Getenv("SIYUAN_WORKSPACE_PATH")
}
if ws == "" {
ws = filepath.Join(homeDir, "SiYuan")
}
if fi, err := os.Stat(ws); err != nil || !fi.IsDir() {
log.Fatalf("workspace not found: %s — create it or pass --workspace", ws)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- not a valid workspace: %s
- appearance files not found at [%s]
- --output is required for docx
- template already exists, use --overwrite to replace: %s
- resolve assets directory [%s] failed: %w
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/f010475027c195eb.
Report an issue: GitHub.