weaviate/weaviate · error
err.Error() (swagger template parse failure)
Error message
err.Error() (swagger template parse failure)
What it means
If the embedded swaggerTemplate cannot be parsed by Go's html/template package, renderSwagger writes the raw parse error to the response with HTTP 500. Template parsing happens at request time (not startup), so a malformed swaggerTemplate constant would surface as a per-request 500. In a released build the template is a compile-time constant and valid, so this error almost always indicates a modified/custom binary or templating regression.
Source
Thrown at adapters/handlers/rest/swagger_middleware/swagger_middleware.go:55
next.ServeHTTP(w, r)
}
})
}
// renderswagger renders the swagger GUI
func renderSwagger(w http.ResponseWriter, r *http.Request) {
w.Header().Set("WWW-Authenticate", `Basic realm="Provide your key and token (as username as password respectively)"`)
user, password, authOk := r.BasicAuth()
if !authOk {
http.Error(w, "Not authorized", http.StatusUnauthorized)
return
}
t := template.New("Swagger")
t, err := t.Parse(swaggerTemplate)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
// Create result string
d := templateData{
Prefix: fmt.Sprintf("https://cdn.jsdelivr.net/npm/swagger-ui-dist@%s", swaggerUIVersion),
APIKey: user,
APIToken: password,
}
err = t.ExecuteTemplate(w, "index", d)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
// tmpl is the page template to render GraphiQLView on GitHub (pinned to 75aa4b6d11)
Solutions
- Check the error body — it is the raw template parse message naming the line/position of the syntax problem; fix that spot in swaggerTemplate in adapters/handlers/rest/swagger_middleware/swagger_middleware.go.
- If running a custom build, revert to the upstream template or validate it: parse it in a small Go test (template.New("Swagger").Parse(tmpl)) before deploying.
- Rebuild the binary from unmodified sources to rule out accidental local edits.
- If it occurs on an official release image, report upstream with the exact error text.
Example fix
// before (invalid template)
const swaggerTemplate = `{{ if .Prefix }...`
// after (balanced action)
const swaggerTemplate = `{{ if .Prefix }}...{{ end }}` Defensive patterns
Strategy: validation
Validate before calling
// validate the template parses at build/startup time
tmpl, err := template.New("Swagger").Parse(swaggerTemplate)
if err != nil {
panic(fmt.Sprintf("swagger template invalid: %v", err))
} Try / catch
// server-side guard if customizing the handler
t, err := t.Parse(swaggerTemplate)
if err != nil {
http.Error(w, "swagger template invalid: "+err.Error(), http.StatusInternalServerError)
return
} Prevention
- Keep swaggerTemplate as an unmodified compile-time constant; validate with a unit test that parses and executes it into a buffer.
- When customizing, run template.New(...).Parse in a quick test before deploying.
- Enable go vet / template tooling to catch malformed {{ }} actions in review.
- Pin and review vendored/forked copies of the middleware after upstream updates.
When it happens
Trigger: A request to the Swagger UI endpoint where t.Parse(swaggerTemplate) fails — only realistically possible when the swaggerTemplate source has been modified (custom fork/patch, build-time injection) and contains invalid template syntax such as unbalanced {{ }} braces or an unknown directive.
Common situations: Patching the template to customize the swagger page and introducing a typo like {{ .Prefix } or stray braces; copying the template from a different Go version/context with incompatible syntax; vendoring/fork drift after an upstream update of swaggerUIVersion or the template.
Related errors
- err.Error() (swagger template execution failure)
- date aggregator state missing from remote shard result, the
- malformed date aggregator pairs in remote shard result
- malformed date aggregator pair in remote shard result
- unknown datatype for aggregation type reference: ${dataType}
AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04).
Data as JSON: /api/errors/6bcbd45b26f5da23.
Report an issue: GitHub.