henrygd/beszel · error

failed to find systems collection: %v

Error message

failed to find systems collection: %v

What it means

While creating systems from config.yml that don't yet exist, SyncSystems looks up the PocketBase collection named/id 'systems' via h.FindCollectionByNameOrId. This error wraps a failure of that lookup, meaning the collection is missing or the name doesn't match. SyncSystems aborts so partial syncs don't occur mid-loop.

Source

Thrown at internal/hub/config/config.go:126

			existingSystem.Set("users", sysConfig.Users)
			existingSystem.Set("port", sysConfig.Port)
			if err := h.Save(existingSystem); err != nil {
				return err
			}

			// Only update token if one is specified in config, otherwise preserve existing token
			if sysConfig.Token != "" {
				if err := updateFingerprintToken(h, existingSystem.Id, sysConfig.Token); err != nil {
					return err
				}
			}

			delete(existingSystemsMap, key)
		} else {
			// Create new system
			systemsCollection, err := h.FindCollectionByNameOrId("systems")
			if err != nil {
				return fmt.Errorf("failed to find systems collection: %v", err)
			}
			newSystem := core.NewRecord(systemsCollection)
			newSystem.Set("name", sysConfig.Name)
			newSystem.Set("host", sysConfig.Host)
			newSystem.Set("port", sysConfig.Port)
			newSystem.Set("users", sysConfig.Users)
			newSystem.Set("info", system.Info{})
			newSystem.Set("status", "pending")
			if err := h.Save(newSystem); err != nil {
				return fmt.Errorf("failed to create new system: %v", err)
			}

			// For new systems, generate token if not provided
			token := sysConfig.Token
			if token == "" {
				token = uuid.New().String()
			}

View on GitHub (pinned to b38fb7dafa)

Solutions

  1. Run your schema migrations so the 'systems' collection is created before calling SyncSystems.
  2. Verify the collection name in the PocketBase admin UI matches 'systems' exactly (case-sensitive).
  3. Create the collection manually with the expected fields (name, host, port, users, info, status) if migrations are not used.
  4. Confirm the app is connected to the intended PocketBase database file/environment.

Example fix

// before: fresh DB, no migrations
err := app.SyncSystems() // failed to find systems collection: ...

// after: ensure migrations register the collection
func init() {
    m.OnServe().BindFunc(func(e *core.ServeEvent) error {
        ensureSystemsCollection(e.App)
        return e.Next()
    })
}
Defensive patterns

Strategy: validation

Validate before calling

collections, err := app.ListCollections()
if err != nil { return err }
found := false
for _, c := range collections { if c.Name == "systems" { found = true } }
if !found { return fmt.Errorf("run migrations first: 'systems' collection missing") }

Type guard

func systemsCollectionExists(app *pocketbase.PocketBase) bool {
    _, err := app.FindCollectionByNameOrId("systems")
    return err == nil
}

Try / catch

if err := SyncSystems(); err != nil {
    if strings.Contains(err.Error(), "failed to find systems collection") {
        return fmt.Errorf("apply DB migrations to create 'systems' collection, then retry: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling SyncSystems on a PocketBase instance where no collection named 'systems' exists (fresh database that never ran migrations), or the collection was renamed/deleted.

Common situations: Deploying to a brand-new PocketBase DB without applying schema migrations; renaming the collection in the admin UI while config sync still references 'systems'; pointing the hub at the wrong PocketBase app/database.

Related errors


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