{"record":{"id":"7133f8654bbc57a1","repo":"OpenNHP/opennhp","slug":"config-load-error","errorCode":null,"errorMessage":"config load error","messagePattern":"config load error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"endpoints/ac/config.go","lineNumber":26,"sourceCode":"\t\"path/filepath\"\n\t\"strconv\"\n\t\"strings\"\n\n\ttoml \"github.com/pelletier/go-toml/v2\"\n\n\t\"github.com/OpenNHP/opennhp/nhp/common/clusterconfig\"\n\t\"github.com/OpenNHP/opennhp/nhp/core\"\n\t\"github.com/OpenNHP/opennhp/nhp/etcd\"\n\t\"github.com/OpenNHP/opennhp/nhp/log\"\n\t\"github.com/OpenNHP/opennhp/nhp/utils\"\n)\n\nvar (\n\tbaseConfigWatch io.Closer\n\thttpConfigWatch io.Closer\n\tserverPeerWatch io.Closer\n\n\terrLoadConfig = fmt.Errorf(\"config load error\")\n)\n\nconst (\n\tFilterMode_IPTABLES = iota // 0\n\tFilterMode_EBPFXDP         // 1\n)\n\n// ACEtcdConfig is the remote-config (etcd) shape. Servers carries the\n// shared cluster schema so the etcd value is identical to the on-disk\n// server.toml. The previous Endpoints-string form lived only on this\n// branch and is removed in the AC → ClusterConfig migration; redeploy\n// any etcd values written under that schema.\ntype ACEtcdConfig struct {\n\tBaseConfig Config\n\tHttpConfig HttpConfig\n\tServers    []*clusterconfig.ClusterConfig\n}\n","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/endpoints/ac/config.go#L8-L44","documentation":"errLoadConfig is a sentinel error returned by UdpAC.updateBaseConfig and UdpAC.updateHttpConfig when a config reload callback panics; utils.CatchPanicThenRun recovers the panic and the named return err is set to errLoadConfig so callers see a config load failure instead of a crash. It signals that a config file (base, http, or server peer) could not be applied.","triggerScenarios":"A panic occurs inside the config-watch/reload code path of updateBaseConfig (endpoints/ac/config.go:242) or updateHttpConfig (endpoints/ac/config.go:278), e.g. nil dereference or type assertion failure while applying a freshly loaded Config/HttpConfig from the TOML watcher.","commonSituations":"Editing config.toml or http.toml while nhp-ac is running with a value that makes the reload code panic (wrong type in TOML that slips past unmarshal, missing map entries); hot-reload race where the watcher fires with a partially written file.","solutions":["Inspect ac logs immediately preceding the panic to find the actual panic value and stack from utils.CatchPanicThenRun","Validate the TOML files (config.toml, http.toml) types and required fields before saving; restart nhp-ac with known-good config","Fix the reload code to validate Config fields before mutating live state, so bad files return a normal error instead of panicking","Check for a race between the file watcher and readers sharing the config struct; add locking or snapshot swap"],"exampleFix":"// before\nfunc (a *UdpAC) updateBaseConfig(conf Config) (err error) {\n\tutils.CatchPanicThenRun(func() { err = errLoadConfig })\n\t...\n}\n// after\nfunc (a *UdpAC) updateBaseConfig(conf Config) (err error) {\n\tif conf.ListenAddress == \"\" || conf.PrivateKeyBase64 == \"\" {\n\t\treturn fmt.Errorf(\"invalid base config: missing required fields\")\n\t}\n\tutils.CatchPanicThenRun(func() { err = errLoadConfig })\n\t...\n}","handlingStrategy":"try-catch","validationCode":"// validate TOML before save\nvar c ac.Config\nif _, err := toml.DecodeFile(\"config.toml\", &c); err != nil { return err }\nif c.ListenAddress == \"\" || c.PrivateKeyBase64 == \"\" { return fmt.Errorf(\"config.toml incomplete\") }","typeGuard":null,"tryCatchPattern":"if err := a.UpdateBaseConfig(conf); err != nil {\n\tif errors.Is(err, ac.ErrLoadConfig) {\n\t\tlog.Error(\"config reload panicked; keeping previous config\")\n\t}\n}","preventionTips":["Validate TOML files with a dry-run decode before saving","Write config atomically (temp file + rename) so watchers never see partial files","Add unit tests for the reload path with malformed configs"],"tags":["config","go","hot-reload","panic"],"backgroundTag":"invalid-config-value","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}