henrygd/beszel · warning

system not found

Error message

system not found

What it means

Returned by RemoveSystem when the given systemID does not exist in the manager's store (sm.systems.GetOk fails). It signals the cleanup request referenced a system that was already removed or never added.

Source

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

	// 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)
	if !ok {
		return errors.New("system not found")
	}

	// Stop the update goroutine
	if system.cancel != nil {
		system.cancel()
	}

	// Clean up all connections
	system.closeSSHConnection()
	system.closeWebSocketConnection()
	sm.systems.Remove(systemID)
	return nil
}

// AddRecord creates a System instance from a database record and adds it to the manager.
// If a system with the same ID already exists, it's removed first to ensure clean state.
// If no system instance is provided, a new one is created.
// This method is typically called when systems are created or their status changes to pending.

View on GitHub (pinned to b38fb7dafa)

Solutions

  1. Check existence (sm.Has(systemID)) before removing, or treat 'not found' as success
  2. Deduplicate removal paths so a system is removed exactly once
  3. Refresh the system ID from the current record/store instead of a cached value

Example fix

// before
if err := sm.RemoveSystem(id); err != nil {
    return err
}
// after
if err := sm.RemoveSystem(id); err != nil && !errors.Is(err, systems.ErrSystemNotFound) {
    return err // already removed is fine
}
Defensive patterns

Strategy: try-catch

Validate before calling

if !manager.Has(systemID) {
    return nil // nothing to remove
}

Try / catch

if err := manager.RemoveSystem(id); err != nil {
    if strings.Contains(err.Error(), "system not found") { return nil }
    return err
}

Prevention

When it happens

Trigger: Calling RemoveSystem with an ID that was never added, or that was already removed (e.g. double invocation from onRecordAfterDeleteSuccess and RemoveAllSystems, or a stale ID after a token rotation).

Common situations: Race between two deletion paths removing the same system; deleting a record whose system was already purged; mistyped/stale system ID in code or scripts.

Understand the failure class

Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.

Related errors


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