hasura/graphql-engine · error
cannot fetch template: %w
Error message
cannot fetch template: %w
What it means
BuildConsoleRouter loads the console HTML template (console.gohtml) from the template provider (embedded FS or assets path) for the CLI's console version; if LoadTemplates fails, you get 'cannot fetch template'. Causes are a missing/corrupt embedded asset, an unreadable static asset directory, or a template path that doesn't exist.
Source
Thrown at cli/pkg/console/consoleserver.go:155
) (*gin.Engine, error) {
var op errors.Op = "console.BuildConsoleRouter"
// An Engine instance with the Logger and Recovery middleware already attached.
gin.SetMode(gin.ReleaseMode)
r := gin.New()
if !templateProvider.DoTemplateExist(
templateProvider.BasePath() + templateVersion + templateProvider.TemplateFilename(),
) {
templateVersion = "latest"
}
// Template console.gohtml
templateRender, err := templateProvider.LoadTemplates(
templateProvider.BasePath()+templateVersion+"/",
templateProvider.TemplateFilename(),
)
if err != nil {
return nil, errors.E(op, fmt.Errorf("cannot fetch template: %w", err))
}
r.HTMLRender = templateRender
if staticDir != "" {
r.Use(static.Serve("/static", static.LocalFile(staticDir, false)))
opts["cliStaticDir"] = staticDir
}
r.GET("/*action", func(c *gin.Context) {
c.HTML(http.StatusOK, templateProvider.TemplateFilename(), &opts)
})
return r, nil
}
View on GitHub (pinned to 724551b9ae)
Solutions
- Upgrade/reinstall the CLI binary so embedded console assets match the CLI version
- If using --static-dir, verify the directory exists and contains the console assets
- Clear any cached console assets the CLI uses and retry
- Report/avoid patched CLI builds that strip the embed of template assets
Example fix
# before hasura console --static-dir ./missing-assets # cannot fetch template # after hasura console --static-dir ./console-assets # directory with valid assets
Defensive patterns
Strategy: try-catch
Validate before calling
if staticDir != "" {
if info, err := os.Stat(staticDir); err != nil || !info.IsDir() {
return fmt.Errorf("static dir invalid: %s", staticDir)
}
} Try / catch
router, err := console.BuildConsoleRouter(...)
if err != nil {
if strings.Contains(err.Error(), "cannot fetch template") {
// reinstall/upgrade CLI binary to restore embedded assets
}
} Prevention
- Use official CLI release binaries
- Keep --static-dir pointing at a complete, existing assets dir
- Re-download assets after CLI upgrades
When it happens
Trigger: Starting `hasura console` (or an API server that builds the console router) when the embedded console assets for the pinned templateVersion can't be read, or the static assets directory was moved/removed, so LoadTemplates returns an error.
Common situations: Using a custom/old CLI build where console assets weren't embedded; pointing --static-dir to a non-existent path; upgrading the CLI with corrupted cached assets; disk/full or permission issues reading the embedded FS.
Related errors
- error reading from file: path: %s :%w
- error serving console: %w
- error creating migrate instance: %w
- error starting server: %w
- cannot create console server: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/fa62f5b4c94c9d87.
Report an issue: GitHub.