siyuan-note/siyuan · error
--name is required
Error message
--name is required
What it means
Thrown by the `template save-as` cobra subcommand when `--name` is empty (after `--id` passed). `--name` is the template name (without extension); the resulting file is `<name>.md` under `data/templates/`. An empty name would create an invalid filename, so it is rejected before `model.DocSaveAsTemplate` runs. `--dry-run` is honored only after both required flags pass.
Source
Thrown at kernel/cli/cmd/template.go:140
if err != nil {
return err
}
fmt.Print(dom)
return nil
},
}
var templateSaveAsCmd = &cobra.Command{
Use: "save-as --id <id> --name <name>",
Short: "Save a document as a template",
RunE: func(cmd *cobra.Command, args []string) error {
id, _ := cmd.Flags().GetString("id")
name, _ := cmd.Flags().GetString("name")
if id == "" {
return fmt.Errorf("--id is required")
}
if name == "" {
return fmt.Errorf("--name is required")
}
overwrite, _ := cmd.Flags().GetBool("overwrite")
if dryRun {
fmt.Printf("[dry-run] Would save document %s as template \"%s\"\n", id, name)
return nil
}
code, err := model.DocSaveAsTemplate(id, name, 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
},
}
View on GitHub (pinned to 251596fc0d)
Solutions
- Provide a non-empty template name: `siyuan template save-as --id <id> --name <name>`.
- Add `--overwrite` if a template with that name already exists.
Example fix
// before siyuan template save-as --id 20240101000000abc123 // after siyuan template save-as --id 20240101000000abc123 --name daily
Defensive patterns
Strategy: validation
Validate before calling
if name == "" {
return errors.New("--name is required: pass a template name without extension")
}
// siyuan template save-as --id <id> --name <name> Prevention
- Provide a non-empty template name (no `.md` extension needed).
- Add `--overwrite` if re-saving an existing template name.
When it happens
Trigger: Running `siyuan template save-as --id <id>` with no `--name`, or `--name ""`.
Common situations: Providing the document but forgetting to name the template; passing an unset shell variable as the name.
Related errors
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/84ea240f7016d930.
Report an issue: GitHub.