siyuan-note/siyuan · error

--path is required

Error message

--path is required

What it means

Returned by `resolveTemplateAbs` when the incoming path string is empty. This helper resolves a user-supplied template path under `data/templates/` and rejects an empty value before doing any filesystem work; it is shared by the `get`, `remove`, and `render` template subcommands that all declare a `--path` flag in `init()`.

Source

Thrown at kernel/cli/cmd/template.go:192

			return nil
		}
		code, err := model.CreateTemplate(name, content, overwrite)
		if err != nil {
			return err
		}
		if code == 1 {
			return fmt.Errorf("template already exists, use --overwrite to replace: %s", name)
		}
		fmt.Printf("%s.md\n", name)
		return nil
	},
}

// resolveTemplateAbs 把模板路径解析为 data/templates 下的绝对路径,拒绝越界。
// 接受绝对路径或相对 data/templates 的相对路径。
func resolveTemplateAbs(p string) (string, error) {
	if p == "" {
		return "", fmt.Errorf("--path is required")
	}
	abs := p
	if !filepath.IsAbs(abs) {
		abs = filepath.Join(util.DataDir, "templates", p)
	}
	abs = filepath.Clean(abs)
	templatesBase := filepath.Clean(filepath.Join(util.DataDir, "templates"))
	rel, err := filepath.Rel(templatesBase, abs)
	if err != nil || strings.HasPrefix(rel, "..") || rel == ".." {
		return "", fmt.Errorf("path escapes templates dir: %s", p)
	}
	return abs, nil
}

func init() {
	templateGetCmd.Flags().String("path", "", "template path (absolute or relative to data/templates)")
	templateRemoveCmd.Flags().String("path", "", "template path (absolute or relative to data/templates)")
	templateRenderCmd.Flags().String("path", "", "template path (absolute or relative to data/templates)")

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Supply `--path` as either an absolute path or a path relative to `data/templates`, e.g. `siyuan template get --path foo.md`.
  2. In scripts, assert the path variable is non-empty before invoking the CLI.
  3. Run `siyuan template search` to list available template paths if unsure.

Example fix

// before
siyuan template get
// after
siyuan template get --path foo.md
Defensive patterns

Strategy: validation

Validate before calling

// Validate before resolving:
if strings.TrimSpace(p) == "" {
    return "", fmt.Errorf("--path is required")
}

Prevention

When it happens

Trigger: Running `siyuan template get`, `template remove`, or `template render` without the `--path` flag, or with `--path ""`. These commands cannot locate a template without a path.

Common situations: Forgetting the flag when scripting; passing an environment variable that expanded to empty; mixing up `--name` (used by create/saveAs) with `--path` (used by get/remove/render).

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/2ee19b3e7853465b. Report an issue: GitHub.