siyuan-note/siyuan · error
--path is required
Error message
--path is required
What it means
resolveTemplateAbs resolves a template path to an absolute path under data/templates. The error is thrown when the caller passes an empty string as the path, because there is nothing to resolve. The CLI flag --path is the only way to supply it, so an empty value means the command was invoked without the flag.
Solutions
- Re-run the command with the --path flag set, e.g. --path my-template or an absolute path.
- Check that the variable feeding --path is not empty in your script/config.
- Use the flag help (`template --help`) to confirm the expected path form (absolute or relative to data/templates).
Example fix
// before template get // after template get --path templates/my-template.sy
Defensive patterns
Strategy: validation
Validate before calling
if (!path || path.trim() === "") throw new Error("--path must be set before calling template commands"); Prevention
- Always pass --path explicitly in scripts; never rely on defaults.
- Assert non-empty config variables before interpolating into CLI arguments.
- Use `--help` to confirm required flags before automation.
When it happens
Trigger: Running a template subcommand (e.g. `siyuan template ...`) without setting the --path flag, or setting --path "" explicitly, so resolveTemplateAbs receives p == "".
Common situations: Scripting or automating the CLI and forgetting the --path flag; copying an example command and omitting the placeholder; a config file or shell variable expanding to an empty value for --path.
Understand the failure class
Background: "no subcommand specified" and "... is required": CLI errors when a required argument is missing — this error's family across 13 libraries.
Related errors
- --output is required for docx
- path escapes templates dir
- path is required
- appearance files not found at
- assetPath is required for analyze
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/2ee19b3e7853465b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/template.go:204
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 9f775e8a12)