{"record":{"id":"4b0d578c16fe74c1","repo":"sqshq/sampler","slug":"failed-to-find-component-type-v-with-title-v","errorCode":null,"errorMessage":"Failed to find component type %v with title %v","messagePattern":"Failed to find component type (.+?) with title (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"config/config.go","lineNumber":98,"sourceCode":"\t\t\tif component.Title == componentTitle {\n\t\t\t\treturn &c.SparkLines[i].ComponentConfig\n\t\t\t}\n\t\t}\n\tcase TypeAsciiBox:\n\t\tfor i, component := range c.AsciiBoxes {\n\t\t\tif component.Title == componentTitle {\n\t\t\t\treturn &c.AsciiBoxes[i].ComponentConfig\n\t\t\t}\n\t\t}\n\tcase TypeTextBox:\n\t\tfor i, component := range c.TextBoxes {\n\t\t\tif component.Title == componentTitle {\n\t\t\t\treturn &c.TextBoxes[i].ComponentConfig\n\t\t\t}\n\t\t}\n\t}\n\n\tpanic(fmt.Sprintf(\n\t\t\"Failed to find component type %v with title %v\", componentType, componentTitle))\n}\n\nfunc readFile(location *string) *Config {\n\n\tyamlFile, err := ioutil.ReadFile(*location)\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to read config file: %s\", *location)\n\t}\n\n\tcfg := new(Config)\n\terr = yaml.Unmarshal(yamlFile, cfg)\n\n\tif err != nil {\n\t\tlog.Fatalf(\"Failed to read config file: %v\", err)\n\t}\n\n\treturn cfg","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/sqshq/sampler/blob/9bc7ba732d31f32a917ad4b5605f00b76ebe0891/config/config.go#L80-L116","documentation":"Config.Update locates the component config matching a type and title via findComponent; if no component of the given type has the given title, it panics with \"Failed to find component type %v with title %v\". This guards the invariant that runtime updates must reference an existing configured component — a missing match means the update cannot be applied safely.","triggerScenarios":"Calling Update (e.g. from the web/API layer) with a componentType/title pair that does not exist in the loaded Config — wrong title casing, component removed from YAML, or mismatched type (textbox vs run-chart vs gauges...).","commonSituations":"Web UI or API client sending a stale title after the user renamed/removed the component in the YAML; programmatic updates constructing titles by string concatenation; case-sensitivity mismatches between config and request.","solutions":["Verify the component's title in the YAML matches exactly (including case and spaces) what the update request sends","Re-read/reload the config before updating if components were recently added or removed","Replace the panic with an error return: change findComponent to return (*ComponentConfig, error) and have Update propagate it","Add a pre-check in the caller that the component exists before issuing an update"],"exampleFix":"// before\npanic(fmt.Sprintf(\n    \"Failed to find component type %v with title %v\", componentType, componentTitle))\n// after\nreturn nil, fmt.Errorf(\"failed to find component type %v with title %v\", componentType, componentTitle)","handlingStrategy":"validation","validationCode":"func componentExists(cfg *config.Config, ctype, title string) bool {\n    // iterate configured components and compare Title/type before Update\n    return findIndex(cfg, ctype, title) >= 0\n}","typeGuard":null,"tryCatchPattern":"func updateSafe(cfg *config.Config, ctype, title string, data []byte) (err error) {\n    defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"update failed: %v\", r) } }()\n    cfg.Update(ctype, title, data)\n    return nil\n}","preventionTips":["Keep update requests and YAML titles in sync (exact match, case-sensitive)","Reload config snapshots before issuing updates after edits","Refactor findComponent to return an error instead of panicking"],"tags":["go","panic","config","lookup-failed"],"backgroundTag":"entity-not-found","analyzedSha":"9bc7ba732d31f32a917ad4b5605f00b76ebe0891","analyzedAt":"2026-09-06T08:38:02.595Z","contentChangedAt":"2026-09-06T08:38:02.595Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}