{"record":{"id":"79a46baf962aa5a4","repo":"henrygd/beszel","slug":"system-missing-required-fields","errorCode":null,"errorMessage":"system missing required fields","messagePattern":"system missing required fields","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hub/systems/system_manager.go","lineNumber":259,"sourceCode":"\treturn e.Next()\n}\n\n// onRecordAfterDeleteSuccess is called after a system record is successfully deleted.\n// It removes the system from the manager and cleans up all associated resources.\nfunc (sm *SystemManager) onRecordAfterDeleteSuccess(e *core.RecordEvent) error {\n\tsm.RemoveSystem(e.Record.Id)\n\treturn e.Next()\n}\n\n// AddSystem adds a system to the manager and starts monitoring it.\n// It validates required fields, initializes the system context, and starts the update goroutine.\n// Returns error if a system with the same ID already exists.\nfunc (sm *SystemManager) AddSystem(sys *System) error {\n\tif sm.systems.Has(sys.Id) {\n\t\treturn errSystemExists\n\t}\n\tif sys.Id == \"\" || sys.Host == \"\" {\n\t\treturn errors.New(\"system missing required fields\")\n\t}\n\n\t// Initialize system for monitoring\n\tsys.manager = sm\n\tsys.ctx, sys.cancel = sys.getContext(sm.ctx)\n\tsys.data = &system.CombinedData{}\n\tsm.systems.Set(sys.Id, sys)\n\n\t// Start monitoring in background\n\tgo sys.StartUpdater()\n\treturn nil\n}\n\n// RemoveSystem removes a system from the manager and cleans up all associated resources.\n// It cancels the system's context, closes all connections, and removes it from the store.\n// Returns an error if the system is not found.\nfunc (sm *SystemManager) RemoveSystem(systemID string) error {\n\tsystem, ok := sm.systems.GetOk(systemID)","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/hub/systems/system_manager.go#L241-L277","documentation":"A validation error returned by AddSystem when the System struct lacks mandatory identity: Id or Host is an empty string. Beszel refuses to register a system it cannot identify or connect to.","triggerScenarios":"Calling AddSystem with sys.Id == \"\" or sys.Host == \"\" (checked after the duplicate check in AddSystem).","commonSituations":"Constructing a System manually from incomplete config/YAML; a struct field typo so Host never gets set; deserializing a record where id/host columns are empty.","solutions":["Ensure System.Id and System.Host are populated before calling AddSystem","Validate the config file that seeds the system (id and host keys present, non-empty)","Fix field mapping in code that copies database/config values into the System struct","Log the offending system at the call site to find which record is incomplete"],"exampleFix":"// before\nsys := &systems.System{Name: cfg.Name}\nhub.AddSystem(sys)\n// after\nif cfg.Id == \"\" || cfg.Host == \"\" {\n    return fmt.Errorf(\"system %q: id and host are required\", cfg.Name)\n}\nsys := &systems.System{Id: cfg.Id, Host: cfg.Host, Name: cfg.Name}\nhub.AddSystem(sys)","handlingStrategy":"validation","validationCode":"func validateSystem(sys *System) error {\n    if sys.Id == \"\" { return errors.New(\"system id is required\") }\n    if sys.Host == \"\" { return errors.New(\"system host is required\") }\n    return nil\n}\n// call validateSystem(sys) before manager.AddSystem(sys)","typeGuard":null,"tryCatchPattern":"if err := manager.AddSystem(sys); err != nil {\n    if strings.Contains(err.Error(), \"missing required fields\") {\n        log.Printf(\"invalid system %+v\", sys)\n    }\n    return err\n}","preventionTips":["Validate config before constructing Systems","Use constructors that require id and host","Test config loading with complete fixture data"],"tags":["go","validation","missing-field","system-manager"],"backgroundTag":"missing-required-field","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}