{"record":{"id":"2ee19b3e7853465b","repo":"siyuan-note/siyuan","slug":"path-is-required-2ee19b","errorCode":null,"errorMessage":"--path is required","messagePattern":"--path is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/template.go","lineNumber":192,"sourceCode":"\t\t\treturn nil\n\t\t}\n\t\tcode, err := model.CreateTemplate(name, content, overwrite)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif code == 1 {\n\t\t\treturn fmt.Errorf(\"template already exists, use --overwrite to replace: %s\", name)\n\t\t}\n\t\tfmt.Printf(\"%s.md\\n\", name)\n\t\treturn nil\n\t},\n}\n\n// resolveTemplateAbs 把模板路径解析为 data/templates 下的绝对路径，拒绝越界。\n// 接受绝对路径或相对 data/templates 的相对路径。\nfunc resolveTemplateAbs(p string) (string, error) {\n\tif p == \"\" {\n\t\treturn \"\", fmt.Errorf(\"--path is required\")\n\t}\n\tabs := p\n\tif !filepath.IsAbs(abs) {\n\t\tabs = filepath.Join(util.DataDir, \"templates\", p)\n\t}\n\tabs = filepath.Clean(abs)\n\ttemplatesBase := filepath.Clean(filepath.Join(util.DataDir, \"templates\"))\n\trel, err := filepath.Rel(templatesBase, abs)\n\tif err != nil || strings.HasPrefix(rel, \"..\") || rel == \"..\" {\n\t\treturn \"\", fmt.Errorf(\"path escapes templates dir: %s\", p)\n\t}\n\treturn abs, nil\n}\n\nfunc init() {\n\ttemplateGetCmd.Flags().String(\"path\", \"\", \"template path (absolute or relative to data/templates)\")\n\ttemplateRemoveCmd.Flags().String(\"path\", \"\", \"template path (absolute or relative to data/templates)\")\n\ttemplateRenderCmd.Flags().String(\"path\", \"\", \"template path (absolute or relative to data/templates)\")","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/template.go#L174-L210","documentation":"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()`.","triggerScenarios":"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.","commonSituations":"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).","solutions":["Supply `--path` as either an absolute path or a path relative to `data/templates`, e.g. `siyuan template get --path foo.md`.","In scripts, assert the path variable is non-empty before invoking the CLI.","Run `siyuan template search` to list available template paths if unsure."],"exampleFix":"// before\nsiyuan template get\n// after\nsiyuan template get --path foo.md","handlingStrategy":"validation","validationCode":"// Validate before resolving:\nif strings.TrimSpace(p) == \"\" {\n    return \"\", fmt.Errorf(\"--path is required\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Mark the --path flag required on get/remove/render subcommands.","In scripts, assert the path variable is non-empty before invoking the CLI.","Use `siyuan template search` to discover valid paths when unsure."],"tags":["cli","template","validation","flag"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}