glanceapp/glance · error

initializing subrequest %q: %v

Error message

initializing subrequest %q: %v

What it means

Returned by customAPIWidget.initialize when one of the widget's named subrequests fails its CustomAPIRequest.initialize() validation. The %q verb carries the subrequest's map key, telling you exactly which entry under subrequests: is misconfigured.

Source

Thrown at internal/glance/widget-custom-api.go:60

	*CustomAPIRequest `yaml:",inline"`             // the primary request
	Subrequests       map[string]*CustomAPIRequest `yaml:"subrequests"`
	Options           customAPIOptions             `yaml:"options"`
	Template          string                       `yaml:"template"`
	Frameless         bool                         `yaml:"frameless"`
	compiledTemplate  *template.Template           `yaml:"-"`
	CompiledHTML      template.HTML                `yaml:"-"`
}

func (widget *customAPIWidget) initialize() error {
	widget.withTitle("Custom API").withCacheDuration(1 * time.Hour)

	if err := widget.CustomAPIRequest.initialize(); err != nil {
		return fmt.Errorf("initializing primary request: %v", err)
	}

	for key := range widget.Subrequests {
		if err := widget.Subrequests[key].initialize(); err != nil {
			return fmt.Errorf("initializing subrequest %q: %v", key, err)
		}
	}

	if widget.Template == "" {
		return errors.New("template is required")
	}

	compiledTemplate, err := template.New("").Funcs(customAPITemplateFuncs).Parse(widget.Template)
	if err != nil {
		return fmt.Errorf("parsing template: %w", err)
	}

	widget.compiledTemplate = compiledTemplate

	return nil
}

func (widget *customAPIWidget) update(ctx context.Context) {

View on GitHub (pinned to 91324e8de7)

Solutions

  1. Match the quoted key in the message to the entry under subrequests: in your page config.
  2. Validate that entry's body-type (json|string) and body shape exactly as you would for the primary request.
  3. Confirm the subrequest has its own url and any auth headers it needs.
  4. After fixing, reload glance config; initialization errors surface at page load.

Example fix

# before
subrequests:
  details:
    url: https://example.com/detail
    body-type: xml

# after
subrequests:
  details:
    url: https://example.com/detail
    body-type: json
Defensive patterns

Strategy: validation

Validate before calling

for key, sub := range widget.Subrequests {
    if sub == nil || sub.URL == "" {
        return fmt.Errorf("subrequest %q missing url", key)
    }
    if sub.BodyType != "" && sub.BodyType != "json" && sub.BodyType != "string" {
        return fmt.Errorf("subrequest %q: bad body-type %q", key, sub.BodyType)
    }
}

Try / catch

if err := widget.initialize(); err != nil {
    // message names the failing subrequest key — surface it verbatim
    slog.Error("custom-api init failed", "widget", title, "error", err)
}

Prevention

When it happens

Trigger: A subrequests entry whose body-type is not json/string, whose body cannot be marshaled, or which otherwise fails the same per-request validation used for the primary request; the error names the key, e.g. initializing subrequest "details": ...

Common situations: One subrequest key has a typo'd field; YAML anchors reused across requests carrying an incompatible field; adding a new subrequest by copy-paste and forgetting to update its body-type.

Related errors


AI-assisted analysis of glanceapp/glance@91324e8de7 (2026-08-15). Data as JSON: /api/errors/2b1e757cfe13be30. Report an issue: GitHub.