ory/hydra · error
could not parse template %s
Error message
could not parse template %s
What it means
When a migration file is a template (usingTemplate is true), its content is parsed with Go's text/template (with SQLTemplateFuncs registered). If template.Parse fails on the file bytes, the underlying parse error is wrapped with 'could not parse template %s' naming the migration file path.
Source
Thrown at oryx/popx/migration_content.go:24
import (
"bytes"
"text/template"
"github.com/pkg/errors"
"github.com/ory/pop/v6"
"github.com/ory/x/dbal"
)
func ParameterizedMigrationContent(params map[string]interface{}) func(mf Migration, c *pop.Connection, r []byte, usingTemplate bool) (string, error) {
return func(mf Migration, c *pop.Connection, b []byte, usingTemplate bool) (string, error) {
content := ""
if usingTemplate {
t := template.New("migration")
t.Funcs(SQLTemplateFuncs)
t, err := t.Parse(string(b))
if err != nil {
return "", errors.Wrapf(err, "could not parse template %s", mf.Path)
}
var bb bytes.Buffer
err = t.Execute(&bb, struct {
IsSQLite bool
IsCockroach bool
IsMySQL bool
IsMariaDB bool
IsPostgreSQL bool
DialectDetails *pop.ConnectionDetails
Parameters map[string]interface{}
}{
IsSQLite: c.Dialect.Name() == "sqlite3",
IsCockroach: c.Dialect.Name() == "cockroach",
IsMySQL: c.Dialect.Name() == "mysql",
IsMariaDB: c.Dialect.Name() == "mariadb",
IsPostgreSQL: dbal.IsPostgresCompatible(c.Dialect.Name()),
DialectDetails: c.Dialect.Details(),
Parameters: params,View on GitHub (pinned to 4174065ffb)
Solutions
- Open the migration file named in the message and fix the template syntax (balance {{ if }}/{{ end }}, {{ range }})
- Verify any called functions exist in SQLTemplateFuncs
- Escape literal braces that must not be interpreted as template actions
- Test the template by running the migration against a dev database to confirm it parses
Example fix
// before (migration.up.sql)
{{ if .IsSQLite }}CREATE TABLE t...
// after
{{ if .IsSQLite }}CREATE TABLE t...{{ end }} Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate template syntax of migration files before running migrations
func templateParses(path string) error {
b, err := os.ReadFile(path)
if err != nil { return err }
t := template.New("check").Funcs(popx.SQLTemplateFuncs)
_, err = t.Parse(string(b))
return err
} Prevention
- Run a lint step that parses all .sql migrations as templates in CI
- Balance every {{ if }}/{{ range }} with {{ end }} before committing
- Escape literal '{{' in SQL with a delims change or template comment
- Only call functions documented in SQLTemplateFuncs
When it happens
Trigger: A .sql migration containing malformed Go template syntax — e.g. an unclosed {{ if }}, unknown template function, or stray {{ }} — passed through the templated migration path.
Common situations: Typos in template directives like {{ if .IsSQLite }} without an {{ end }}; calling a func not present in SQLTemplateFuncs; editing a templated migration and breaking syntax; copy-pasting SQL containing '{{' sequences.
Related errors
- could not execute migration template %s
- migration %s has no corresponding down migration
- problem checking for migration version %s
- unsupported dialect
- error processing %s
AI-assisted analysis of ory/hydra@4174065ffb (2026-09-03).
Data as JSON: /api/errors/d127419827ee8ead.
Report an issue: GitHub.