{"record":{"id":"ecea9098372e5b5f","repo":"henrygd/beszel","slug":"failed-to-parse-config-yml-v","errorCode":null,"errorMessage":"failed to parse config.yml: %v","messagePattern":"failed to parse config\\.yml: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/hub/config/config.go","lineNumber":43,"sourceCode":"\tHost  string   `yaml:\"host\"`\n\tPort  uint16   `yaml:\"port,omitempty\"`\n\tToken string   `yaml:\"token,omitempty\"`\n\tUsers []string `yaml:\"users\"`\n}\n\n// Syncs systems with the config.yml file\nfunc SyncSystems(e *core.ServeEvent) error {\n\th := e.App\n\tconfigPath := filepath.Join(h.DataDir(), \"config.yml\")\n\tconfigData, err := os.ReadFile(configPath)\n\tif err != nil {\n\t\treturn nil\n\t}\n\n\tvar config config\n\terr = yaml.Unmarshal(configData, &config)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to parse config.yml: %v\", err)\n\t}\n\n\tif len(config.Systems) == 0 {\n\t\tlog.Println(\"No systems defined in config.yml.\")\n\t\treturn nil\n\t}\n\n\tvar firstUser *core.Record\n\n\t// Create a map of email to user ID\n\tuserEmailToID := make(map[string]string)\n\tusers, err := h.FindAllRecords(\"users\", dbx.NewExp(\"id != ''\"))\n\tif err != nil {\n\t\treturn err\n\t}\n\tif len(users) > 0 {\n\t\tfirstUser = users[0]\n\t\tfor _, user := range users {","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/henrygd/beszel/blob/b38fb7dafa60812cc22e6a84ce313e94f1ce0a32/internal/hub/config/config.go#L25-L61","documentation":"SyncSystems reads config.yml and unmarshals it with yaml.Unmarshal into the internal config struct. This error wraps any YAML parsing or structural decoding failure, meaning the file could not be interpreted as valid YAML matching the expected schema. SyncSystems aborts before touching any PocketBase records.","triggerScenarios":"Calling SyncSystems when configData contains invalid YAML — bad indentation, tabs instead of spaces, unquoted special characters, or fields whose types don't match the config struct (e.g. port as a string instead of int).","commonSituations":"Hand-edited config.yml with a tab character or wrong indentation; YAML anchors/aliases or multiline strings misused; a value like `port: \"8080\"` where an int is expected; encoding issues (BOM, non-UTF8) introduced by editors.","solutions":["Read the wrapped %v message — it names the exact line and YAML problem (e.g. 'line 4: cannot unmarshal !!str into int').","Validate the file with a linter: `yamllint config.yml` or paste into a YAML validator; replace tabs with spaces.","Fix field types to match the schema (systems list with name/host/port/users fields, port numeric).","Restore from a known-good config or version-controlled copy, then re-run SyncSystems."],"exampleFix":"// before: invalid config.yml\ntab-indented: true\n\t systems:\n  - name: web\n\n// after: consistent two-space indentation, correct types\nsystems:\n  - name: web\n    host: 10.0.0.5\n    port: 22","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(\"config.yml\")\nif err != nil { return err }\nvar probe map[string]any\nif err := yaml.Unmarshal(data, &probe); err != nil {\n    return fmt.Errorf(\"config.yml is not valid YAML: %w\", err)\n}\nif _, ok := probe[\"systems\"]; !ok { return fmt.Errorf(\"config.yml missing 'systems' key\") }","typeGuard":"func isYAMLSyntaxError(err error) bool {\n    var te *yaml.TypeError\n    if errors.As(err, &te) { return false }\n    return err != nil // unmarshal errors that aren't TypeError are syntax errors\n}","tryCatchPattern":"if err := SyncSystems(); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse config.yml\") {\n        return fmt.Errorf(\"fix config.yml before syncing: %w\", err) // do not retry until edited\n    }\n    return err\n}","preventionTips":["Run yamllint or an editor YAML plugin on config.yml before deploying.","Use spaces, never tabs, and keep indentation consistent.","Keep config.yml in version control so bad edits are reviewable and revertible.","Add a startup-time dry-run parse of config.yml with a clear error message."],"tags":["yaml","config","validation"],"backgroundTag":"yaml-parse-error","analyzedSha":"b38fb7dafa60812cc22e6a84ce313e94f1ce0a32","analyzedAt":"2026-08-31T15:10:10.149Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}