{"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":204,"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":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/template.go#L186-L222","documentation":"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.","triggerScenarios":"Running a template subcommand (e.g. `siyuan template ...`) without setting the --path flag, or setting --path \"\" explicitly, so resolveTemplateAbs receives p == \"\".","commonSituations":"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.","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)."],"exampleFix":"// before\ntemplate get\n// after\ntemplate get --path templates/my-template.sy","handlingStrategy":"validation","validationCode":"if (!path || path.trim() === \"\") throw new Error(\"--path must be set before calling template commands\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["cli","missing-argument","templates"],"backgroundTag":"missing-cli-argument","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}