siyuan-note/siyuan · warning
template already exists, use --overwrite to replace: %s
Error message
template already exists, use --overwrite to replace: %s
What it means
Thrown by the `template save-as` cobra subcommand when `model.DocSaveAsTemplate` returns code 1, meaning a template file with the given name already exists under `data/templates/` and `--overwrite` was not set. The engine returns a status code (1 = exists) rather than a Go error, so the CLI translates it into an actionable message. The error names the conflicting template name.
Source
Thrown at kernel/cli/cmd/template.go:152
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
},
}
var templateCreateCmd = &cobra.Command{
Use: "create --name <name> [--data <markdown> | --file <path>]",
Short: "Create a template from markdown content",
RunE: func(cmd *cobra.Command, args []string) error {
name, _ := cmd.Flags().GetString("name")
if name == "" {
return fmt.Errorf("--name is required")
}
content, err := resolveData(cmd)
if err != nil {
return err
}View on GitHub (pinned to 251596fc0d)
Solutions
- Add `--overwrite` to replace the existing template: `siyuan template save-as --id <id> --name <name> --overwrite`.
- Choose a different `--name` to avoid clobbering.
- Remove the old template first with `siyuan template remove --path <name>.md` if you prefer not to overwrite.
Example fix
// before siyuan template save-as --id 20240101000000abc123 --name daily // after siyuan template save-as --id 20240101000000abc123 --name daily --overwrite
Defensive patterns
Strategy: validation
Validate before calling
// Check for an existing template file before calling save-as without --overwrite.
existing := filepath.Join(util.DataDir, "templates", name+".md")
if _, err := os.Stat(existing); err == nil && !overwrite {
return fmt.Errorf("template already exists: %s — re-run with --overwrite", name)
} Try / catch
// Distinguish the exists-code-1 path from real errors.
code, err := model.DocSaveAsTemplate(id, name, overwrite)
if err != nil { return err }
if code == 1 { /* prompt user, then retry with overwrite=true */ } Prevention
- Use `--overwrite` when re-saving a template you intend to update.
- Pick unique template names in automation to avoid conflicts.
- Pre-check `data/templates/<name>.md` existence before scripting save-as.
When it happens
Trigger: Running `siyuan template save-as --id <id> --name <existingName>` without `--overwrite`, where `<name>.md` already exists in `data/templates/`. Re-running a save-as after a previous successful run with the same name.
Common situations: Iterating on a template and re-saving; two documents saved as templates with the same name; scripting template generation without idempotency checks.
Related errors
- --output is required for docx
- directory not found: %s
- not a valid workspace: %s
- --id is required
- --name is required
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/1b5d86741ad3c401.
Report an issue: GitHub.