Skip to content

Commit

Permalink
add error message for unsupported type
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Aug 29, 2024
1 parent 1802f2b commit 3b7a490
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ func (def TemplateName) funcLit(method *ast.FuncType, files []*ast.File) (*ast.F
},
}, field.Type, token.ASSIGN, errCheck)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("failed to generate parse statements for form field %s: %w", name.Name, err)
}
lit.Body.List = append(lit.Body.List, statements...)
imports = append(imports, parseImports...)
Expand Down
19 changes: 19 additions & 0 deletions generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,25 @@ func execute(response http.ResponseWriter, request *http.Request, writeHeader bo
}
`,
},
{
Name: "F is defined and form has unsupported field type",
Templates: `{{define "GET / F(form)"}}Hello, {{.}}!{{end}}`,
ReceiverPackage: `
-- in.go --
package main
type (
T struct{}
In struct{
ts time.Time
}
)
func (T) F(form In) int { return 0 }
`,
Receiver: "T",
ExpectedError: "failed to generate parse statements for form field ts: unsupported type: time.Time",
},
} {
t.Run(tt.Name, func(t *testing.T) {
ts := template.Must(template.New(tt.Name).Parse(tt.Templates))
Expand Down

0 comments on commit 3b7a490

Please sign in to comment.