{"record":{"id":"ca897157c98ff5e0","repo":"henrygd/beszel","slug":"failed-to-create-new-system-v","errorCode":null,"errorMessage":"failed to create new system: %v","messagePattern":"failed to create new system: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hub/config/config.go","lineNumber":136,"sourceCode":"\t\t\t\t}\n\t\t\t}\n\n\t\t\tdelete(existingSystemsMap, key)\n\t\t} else {\n\t\t\t// Create new system\n\t\t\tsystemsCollection, err := h.FindCollectionByNameOrId(\"systems\")\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to find systems collection: %v\", err)\n\t\t\t}\n\t\t\tnewSystem := core.NewRecord(systemsCollection)\n\t\t\tnewSystem.Set(\"name\", sysConfig.Name)\n\t\t\tnewSystem.Set(\"host\", sysConfig.Host)\n\t\t\tnewSystem.Set(\"port\", sysConfig.Port)\n\t\t\tnewSystem.Set(\"users\", sysConfig.Users)\n\t\t\tnewSystem.Set(\"info\", system.Info{})\n\t\t\tnewSystem.Set(\"status\", \"pending\")\n\t\t\tif err := h.Save(newSystem); err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to create new system: %v\", err)\n\t\t\t}\n\n\t\t\t// For new systems, generate token if not provided\n\t\t\ttoken := sysConfig.Token\n\t\t\tif token == \"\" {\n\t\t\t\ttoken = uuid.New().String()\n\t\t\t}\n\n\t\t\t// Create fingerprint record for new system\n\t\t\tif err := createFingerprintRecord(h, newSystem.Id, token); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\n\t// Delete systems not in config (and their fingerprint records will cascade delete)\n\tfor _, system := range existingSystemsMap {\n\t\tif err := h.Delete(system); err != nil {","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/hub/config/config.go#L118-L154","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: duplicate entry in config.yml\nsystems:\n  - name: web\n    host: 10.0.0.5\n  - name: web        # unique index violation on save\n    host: 10.0.0.6\n\n// after: unique names per system\nsystems:\n  - name: web-1\n    host: 10.0.0.5\n  - name: web-2\n    host: 10.0.0.6","handlingStrategy":"validation","validationCode":"seen := map[string]bool{}\nfor _, s := range cfg.Systems {\n    if s.Name == \"\" || s.Host == \"\" { return fmt.Errorf(\"system entry missing name/host\") }\n    if seen[s.Name] { return fmt.Errorf(\"duplicate system name in config: %s\", s.Name) }\n    seen[s.Name] = true\n}","typeGuard":"func isUniqueViolation(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"validation_not_unique\")\n}","tryCatchPattern":"if err := SyncSystems(); err != nil {\n    var verr validation.Errors\n    if strings.Contains(err.Error(), \"failed to create new system\") {\n        log.Error(\"system record rejected; check field rules/unique indexes\", \"detail\", err)\n        return fmt.Errorf(\"config sync stopped at invalid system entry: %w\", err)\n    }\n    return err\n}","preventionTips":["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."],"tags":["pocketbase","database","validation","config"],"backgroundTag":"record-save-validation-failed","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}