{"record":{"id":"18d07eb89edcd450","repo":"spicetify/cli","slug":"panic-err","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/utils/config.go","lineNumber":150,"sourceCode":"\tspotifyPath := FindAppPath()\n\tprefsFilePath := FindPrefFilePath()\n\n\tif len(spotifyPath) == 0 {\n\t\tPrintError(\"Could not detect Spotify location\")\n\t} else {\n\t\tconfigLayout[\"Setting\"][\"spotify_path\"] = spotifyPath\n\t}\n\n\tif len(prefsFilePath) == 0 {\n\t\tPrintError(\"Could not detect \\\"prefs\\\" file location\")\n\t} else {\n\t\tconfigLayout[\"Setting\"][\"prefs_path\"] = prefsFilePath\n\t}\n\n\tfor sectionName, keyList := range configLayout {\n\t\tsection, err := cfg.NewSection(sectionName)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\tfor keyName, defaultValue := range keyList {\n\t\t\tsection.NewKey(keyName, defaultValue)\n\t\t}\n\t}\n\n\tversion, err := cfg.NewSection(\"Backup\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tversion.Comment = \"DO NOT CHANGE!\"\n\tversion.NewKey(\"version\", \"\")\n\tversion.NewKey(\"with\", \"\")\n\treturn cfg\n}\n\n// FindAppPath finds Spotify location in various possible places\n// of each platform and returns it.","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/spicetify/cli/blob/1f13f736163165234eef4fb792a03f9b5b732aa4/src/utils/config.go#L132-L168","documentation":"getDefaultConfig builds the default INI config with go-ini, iterating over configLayout and creating a section per name via cfg.NewSection. If NewSection returns an error the code panics instead of returning an error. With go-ini, NewSection errors when a section with that name already exists, so this panic fires during ParseConfig's default-config creation if a section name is duplicated.","triggerScenarios":"Running ParseConfig on a fresh install when configLayout contains a duplicate section name (two entries for the same section key), causing cfg.NewSection(sectionName) to return \"section ... already exists\" and the code to panic. Also triggered by any go-ini error from NewSection, e.g. an empty section name.","commonSituations":"A developer added a new key and accidentally created a second map entry for an existing section; configLayout was edited with an empty-string section name; library shipped with a mis-merged config layout map. End users hit it as an immediate crash on first run when the config file doesn't exist yet.","solutions":["Check configLayout for duplicate section names (including hidden duplicates like \"Setting\" vs \" Setting\") and remove them.","Ensure no section name in configLayout is an empty string; give every section a valid non-empty name.","If you control the code, replace panic(err) with returning the error up through ParseConfig so callers can handle it.","Delete any partially written config file and retry, in case a stale/partial default file is implicated."],"exampleFix":"// before\nsection, err := cfg.NewSection(sectionName)\nif err != nil {\n\tpanic(err)\n}\n// after\nsection, err := cfg.NewSection(sectionName)\nif err != nil {\n\treturn nil, fmt.Errorf(\"creating section %q: %w\", sectionName, err)\n}","handlingStrategy":"try-catch","validationCode":"// Go: recover from the panic at the call site of ParseConfig\nfunc safeParseConfig() (cfg interface{}, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = fmt.Errorf(\"config init panicked: %v\", r)\n\t\t}\n\t}()\n\treturn utils.ParseConfig(), nil\n}","typeGuard":null,"tryCatchPattern":"defer func() {\n\tif r := recover(); r != nil {\n\t\tlog.Errorf(\"getDefaultConfig panicked: %v — check configLayout for duplicate section names\", r)\n\t}\n}()","preventionTips":["Keep one canonical entry per section in configLayout; add a startup test asserting unique section names.","Reject empty section names in configLayout before iterating.","Convert panics into returned errors in library code so callers can recover.","Pin/patch the library version if a release shipped with a duplicate-section bug."],"tags":["go","panic","ini","config"],"backgroundTag":"duplicate-ini-section-panic","analyzedSha":"1f13f736163165234eef4fb792a03f9b5b732aa4","analyzedAt":"2026-08-31T18:57:59.754Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}