{"record":{"id":"2b1e757cfe13be30","repo":"glanceapp/glance","slug":"initializing-subrequest-q-v","errorCode":null,"errorMessage":"initializing subrequest %q: %v","messagePattern":"initializing subrequest %q: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/glance/widget-custom-api.go","lineNumber":60,"sourceCode":"\t*CustomAPIRequest `yaml:\",inline\"`             // the primary request\n\tSubrequests       map[string]*CustomAPIRequest `yaml:\"subrequests\"`\n\tOptions           customAPIOptions             `yaml:\"options\"`\n\tTemplate          string                       `yaml:\"template\"`\n\tFrameless         bool                         `yaml:\"frameless\"`\n\tcompiledTemplate  *template.Template           `yaml:\"-\"`\n\tCompiledHTML      template.HTML                `yaml:\"-\"`\n}\n\nfunc (widget *customAPIWidget) initialize() error {\n\twidget.withTitle(\"Custom API\").withCacheDuration(1 * time.Hour)\n\n\tif err := widget.CustomAPIRequest.initialize(); err != nil {\n\t\treturn fmt.Errorf(\"initializing primary request: %v\", err)\n\t}\n\n\tfor key := range widget.Subrequests {\n\t\tif err := widget.Subrequests[key].initialize(); err != nil {\n\t\t\treturn fmt.Errorf(\"initializing subrequest %q: %v\", key, err)\n\t\t}\n\t}\n\n\tif widget.Template == \"\" {\n\t\treturn errors.New(\"template is required\")\n\t}\n\n\tcompiledTemplate, err := template.New(\"\").Funcs(customAPITemplateFuncs).Parse(widget.Template)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"parsing template: %w\", err)\n\t}\n\n\twidget.compiledTemplate = compiledTemplate\n\n\treturn nil\n}\n\nfunc (widget *customAPIWidget) update(ctx context.Context) {","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/glanceapp/glance/blob/91324e8de762702e97b0ac5c8e36271d644d8642/internal/glance/widget-custom-api.go#L42-L78","documentation":"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.","triggerScenarios":"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\": ...","commonSituations":"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.","solutions":["Match the quoted key in the message to the entry under subrequests: in your page config.","Validate that entry's body-type (json|string) and body shape exactly as you would for the primary request.","Confirm the subrequest has its own url and any auth headers it needs.","After fixing, reload glance config; initialization errors surface at page load."],"exampleFix":"# before\nsubrequests:\n  details:\n    url: https://example.com/detail\n    body-type: xml\n\n# after\nsubrequests:\n  details:\n    url: https://example.com/detail\n    body-type: json","handlingStrategy":"validation","validationCode":"for key, sub := range widget.Subrequests {\n    if sub == nil || sub.URL == \"\" {\n        return fmt.Errorf(\"subrequest %q missing url\", key)\n    }\n    if sub.BodyType != \"\" && sub.BodyType != \"json\" && sub.BodyType != \"string\" {\n        return fmt.Errorf(\"subrequest %q: bad body-type %q\", key, sub.BodyType)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := widget.initialize(); err != nil {\n    // message names the failing subrequest key — surface it verbatim\n    slog.Error(\"custom-api init failed\", \"widget\", title, \"error\", err)\n}","preventionTips":["Copy an existing working subrequest as the template for new ones.","Keep subrequest keys short and stable so error messages are actionable.","Re-validate the whole page config after bulk edits (anchors, merges)."],"tags":["config","custom-api","subrequest","widget"],"backgroundTag":null,"analyzedSha":"91324e8de762702e97b0ac5c8e36271d644d8642","analyzedAt":"2026-08-15T14:12:54.279Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}