{"record":{"id":"84ea240f7016d930","repo":"siyuan-note/siyuan","slug":"name-is-required-84ea24","errorCode":null,"errorMessage":"--name is required","messagePattern":"--name is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/template.go","lineNumber":152,"sourceCode":"\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfmt.Print(dom)\n\t\treturn nil\n\t},\n}\n\nvar templateSaveAsCmd = &cobra.Command{\n\tUse:   \"save-as --id <id> --name <name>\",\n\tShort: \"Save a document as a template\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tid, _ := cmd.Flags().GetString(\"id\")\n\t\tname, _ := cmd.Flags().GetString(\"name\")\n\t\tif id == \"\" {\n\t\t\treturn fmt.Errorf(\"--id is required\")\n\t\t}\n\t\tif name == \"\" {\n\t\t\treturn fmt.Errorf(\"--name is required\")\n\t\t}\n\t\toverwrite, _ := cmd.Flags().GetBool(\"overwrite\")\n\t\tif dryRun {\n\t\t\tfmt.Printf(\"[dry-run] Would save document %s as template \\\"%s\\\"\\n\", id, name)\n\t\t\treturn nil\n\t\t}\n\t\tcode, err := model.DocSaveAsTemplate(id, name, 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","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/template.go#L134-L170","documentation":"`siyuan template save-as` validates `--name` (the template file name to create) after `--id`. When the name flag is missing or empty the command returns this error, since a template must be stored under a concrete .md file name.","triggerScenarios":"Running `siyuan template save-as --id <id>` without `--name`, or with `--name \"\"`.","commonSituations":"Providing only the document id; empty name variable in scripts; assuming the command derives a default name from the document title (it does not).","solutions":["Add a name: `siyuan template save-as --id <id> --name mytpl`","Pick a name that does not include the .md extension (it is appended on save)","Quote the value to avoid shell splitting"],"exampleFix":"// before\nsiyuan template save-as --id 20240101120000-abcdefg\n// after\nsiyuan template save-as --id 20240101120000-abcdefg --name mytpl","handlingStrategy":"validation","validationCode":"if [ -z \"$NAME\" ]; then echo \"--name is required\" >&2; exit 2; fi\nsiyuan template save-as --id \"$DOC_ID\" --name \"$NAME\"","typeGuard":null,"tryCatchPattern":"if ! siyuan template save-as --id \"$ID\" --name \"$NAME\"; then\n  echo \"save-as failed; provide --name or --overwrite if it exists\" >&2\nfi","preventionTips":["Always choose a template name up front; there is no default","Exclude the .md extension (added automatically)","Quote the name to avoid shell issues"],"tags":["cli","template","missing-flag"],"backgroundTag":"missing-required-flag","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"}