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 GraphiQL

View on GitHub (pinned to 75aa4b6d11)

Solutions

  1. 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.
  2. 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.
  3. Rebuild the binary from unmodified sources to rule out accidental local edits.
  4. 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

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


AI-assisted analysis of weaviate/weaviate@75aa4b6d11 (2026-09-04). Data as JSON: /api/errors/6bcbd45b26f5da23. Report an issue: GitHub.