{"record":{"id":"649be5902327fbe2","repo":"wtfutil/wtf","slug":"panic-err","errorCode":null,"errorMessage":"panic(err)","messagePattern":"panic\\(err\\)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"cfg/config_files.go","lineNumber":220,"sourceCode":"// to the new, XDG-compatible location\nfunc migrateOldConfig() {\n\tsrcDir, _ := expandHomeDir(WtfConfigDirV1)\n\tdestDir, _ := WtfConfigDir()\n\n\t// If the old config directory doesn't exist, do not move\n\tif _, err := os.Stat(srcDir); os.IsNotExist(err) {\n\t\treturn\n\t}\n\n\t// If the new config directory already exists, do not move\n\tif _, err := os.Stat(destDir); err == nil {\n\t\treturn\n\t}\n\n\t// Time to move\n\terr := Copy(srcDir, destDir)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Delete the old directory if the new one exists\n\tif _, err := os.Stat(destDir); err == nil {\n\t\terr := os.RemoveAll(srcDir)\n\t\tif err != nil {\n\t\t\tfmt.Println(err)\n\t\t}\n\t}\n}\n","sourceCodeStart":202,"sourceCodeEnd":231,"githubUrl":"https://github.com/wtfutil/wtf/blob/bb838c1ccb0f0f3223690df44afdec663d622881/cfg/config_files.go#L202-L231","documentation":"migrateOldConfig moves an old config directory to the new location with Copy and unconditionally panics if the copy fails. This is an intentional fail-fast during app startup (Initialize path): the developers decided that a half-migrated config is unrecoverable, so a panic with the raw error is raised instead of returning an error.","triggerScenarios":"Initialize detects an old config directory and calls Copy(srcDir, destDir); the copy fails due to permission errors (read-only destination), disk full, srcDir unreadable, or destDir existing as a file.","commonSituations":"Upgrading the app under a service account that lacks write permission to ~/.config; running in a container with a read-only filesystem or small disk; stale lock/permission issues after switching users.","solutions":["Read the wrapped panic message to identify the OS-level cause (permission denied, no space, etc.) and fix that filesystem condition","Manually copy the old config directory to the new location yourself, then restart so migration is skipped","Check write permissions on the destination config directory for the user running the app","Ensure sufficient disk space and that destDir is not a regular file"],"exampleFix":"// before\n$ whoami # wrong user, no write access to ~/.config\n# after\nsudo chown -R $(whoami) ~/.config/myapp && restart app","handlingStrategy":"fallback","validationCode":"// check migration preconditions before startup\nif _, err := os.Stat(destDir); err == nil {\n    // already migrated; skip\n}\nif err := unix.Access(filepath.Dir(destDir), unix.W_OK); err != nil {\n    log.Fatalf(\"config dir not writable: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"// recover at startup so a failed migration doesn't kill the process\nfunc safeInit() (ok bool) {\n    defer func() {\n        if r := recover(); r != nil {\n            log.Printf(\"config migration failed: %v\", r)\n            ok = false\n        }\n    }()\n    Initialize(cfgPath)\n    return true\n}","preventionTips":["Run the app as a user with write access to the config directory","Ensure adequate disk space before upgrades","Perform the directory copy manually if the destination already exists to skip migration"],"tags":["go","panic","config-migration","filesystem"],"backgroundTag":"startup-panic-on-migration","analyzedSha":"bb838c1ccb0f0f3223690df44afdec663d622881","analyzedAt":"2026-09-03T17:02:45.030Z","contentChangedAt":"2026-09-03T17:02:45.030Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}