henrygd/beszel · error
failed to create new system: %v
Error message
failed to create new system: %v
What it means
After building a new system record (name, host, port, users, info, status=pending), SyncSystems persists it with h.Save. This error wraps a failure of that save — a PocketBase validation or persistence error. SyncSystems aborts immediately, so systems after the failing one are not synced.
Source
Thrown at internal/hub/config/config.go:136
}
}
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()
}
// Create fingerprint record for new system
if err := createFingerprintRecord(h, newSystem.Id, token); err != nil {
return err
}
}
}
// Delete systems not in config (and their fingerprint records will cascade delete)
for _, system := range existingSystemsMap {
if err := h.Delete(system); err != nil {View on GitHub (pinned to b38fb7dafa)
Solutions
- Read the wrapped %v message — PocketBase save errors list the failing field and rule (e.g. validation_not_unique for name).
- Deduplicate system names in config.yml and avoid running SyncSystems concurrently from multiple instances.
- Ensure every required field is present in each config entry (name, host, port, users).
- Check the SQLite file is writable and not locked (lsof on the db file, check disk space/permissions), then re-run.
Example fix
// before: duplicate entry in config.yml
systems:
- name: web
host: 10.0.0.5
- name: web # unique index violation on save
host: 10.0.0.6
// after: unique names per system
systems:
- name: web-1
host: 10.0.0.5
- name: web-2
host: 10.0.0.6 Defensive patterns
Strategy: validation
Validate before calling
seen := map[string]bool{}
for _, s := range cfg.Systems {
if s.Name == "" || s.Host == "" { return fmt.Errorf("system entry missing name/host") }
if seen[s.Name] { return fmt.Errorf("duplicate system name in config: %s", s.Name) }
seen[s.Name] = true
} Type guard
func isUniqueViolation(err error) bool {
return err != nil && strings.Contains(err.Error(), "validation_not_unique")
} Try / catch
if err := SyncSystems(); err != nil {
var verr validation.Errors
if strings.Contains(err.Error(), "failed to create new system") {
log.Error("system record rejected; check field rules/unique indexes", "detail", err)
return fmt.Errorf("config sync stopped at invalid system entry: %w", err)
}
return err
} Prevention
- Deduplicate system names in config.yml before syncing.
- Run sync from a single instance (leader election or lock) to avoid concurrent-create races.
- Mirror PocketBase collection field requirements (required/unique/format) in your config validation.
- Confirm the SQLite file is writable and not locked before sync jobs.
When it happens
Trigger: Calling SyncSystems when inserting a new system record violates collection rules — missing required fields, a unique 'name' collision created concurrently, a field value of the wrong type/format, or a database write failure (locked/corrupt DB, read-only volume).
Common situations: Two config entries or two concurrent syncs creating the same system name against a unique index; config.yml entry missing a required field; port/host values rejected by field validators; SQLite database file locked by another process or on a read-only mount.
Related errors
- failed to find systems collection: %v
- failed to parse config.yml: %v
- service name is required
- invalid token
- system missing required fields
AI-assisted analysis of henrygd/beszel@b38fb7dafa (2026-08-31).
Data as JSON: /api/errors/ca897157c98ff5e0.
Report an issue: GitHub.