henrygd/beszel · error

system missing required fields

Error message

system missing required fields

What it means

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.

Source

Thrown at internal/hub/systems/system_manager.go:259

	return e.Next()
}

// onRecordAfterDeleteSuccess is called after a system record is successfully deleted.
// It removes the system from the manager and cleans up all associated resources.
func (sm *SystemManager) onRecordAfterDeleteSuccess(e *core.RecordEvent) error {
	sm.RemoveSystem(e.Record.Id)
	return e.Next()
}

// AddSystem adds a system to the manager and starts monitoring it.
// It validates required fields, initializes the system context, and starts the update goroutine.
// Returns error if a system with the same ID already exists.
func (sm *SystemManager) AddSystem(sys *System) error {
	if sm.systems.Has(sys.Id) {
		return errSystemExists
	}
	if sys.Id == "" || sys.Host == "" {
		return errors.New("system missing required fields")
	}

	// Initialize system for monitoring
	sys.manager = sm
	sys.ctx, sys.cancel = sys.getContext(sm.ctx)
	sys.data = &system.CombinedData{}
	sm.systems.Set(sys.Id, sys)

	// Start monitoring in background
	go sys.StartUpdater()
	return nil
}

// RemoveSystem removes a system from the manager and cleans up all associated resources.
// It cancels the system's context, closes all connections, and removes it from the store.
// Returns an error if the system is not found.
func (sm *SystemManager) RemoveSystem(systemID string) error {
	system, ok := sm.systems.GetOk(systemID)

View on GitHub (pinned to b38fb7dafa)

Solutions

  1. Ensure System.Id and System.Host are populated before calling AddSystem
  2. Validate the config file that seeds the system (id and host keys present, non-empty)
  3. Fix field mapping in code that copies database/config values into the System struct
  4. Log the offending system at the call site to find which record is incomplete

Example fix

// before
sys := &systems.System{Name: cfg.Name}
hub.AddSystem(sys)
// after
if cfg.Id == "" || cfg.Host == "" {
    return fmt.Errorf("system %q: id and host are required", cfg.Name)
}
sys := &systems.System{Id: cfg.Id, Host: cfg.Host, Name: cfg.Name}
hub.AddSystem(sys)
Defensive patterns

Strategy: validation

Validate before calling

func validateSystem(sys *System) error {
    if sys.Id == "" { return errors.New("system id is required") }
    if sys.Host == "" { return errors.New("system host is required") }
    return nil
}
// call validateSystem(sys) before manager.AddSystem(sys)

Try / catch

if err := manager.AddSystem(sys); err != nil {
    if strings.Contains(err.Error(), "missing required fields") {
        log.Printf("invalid system %+v", sys)
    }
    return err
}

Prevention

When it happens

Trigger: Calling AddSystem with sys.Id == "" or sys.Host == "" (checked after the duplicate check in AddSystem).

Common situations: 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.

Understand the failure class

Background: "Missing required field" and "field is required" errors: why libraries reject payloads that omit mandatory fields — this error's family across 20 libraries.

Related errors


AI-assisted analysis of henrygd/beszel@b38fb7dafa (2026-08-31). Data as JSON: /api/errors/79a46baf962aa5a4. Report an issue: GitHub.