{"record":{"id":"8eb26948e5edf0c3","repo":"netbirdio/netbird","slug":"failed-to-remove-profile-w","errorCode":null,"errorMessage":"failed to remove profile: %w","messagePattern":"failed to remove profile: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/android/profile_manager.go","lineNumber":233,"sourceCode":"func (pm *ProfileManager) RenameProfile(id string, newName string) error {\n\tif err := pm.serviceMgr.RenameProfile(profilemanager.ID(id), androidUsername, newName); err != nil {\n\t\treturn fmt.Errorf(\"failed to rename profile: %w\", err)\n\t}\n\n\tlog.Infof(\"renamed profile %s to: %s\", id, newName)\n\treturn nil\n}\n\n// RemoveProfile deletes a profile\nfunc (pm *ProfileManager) RemoveProfile(id string) error {\n\tconfigPath, err := pm.getProfileConfigPath(id)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Use ServiceManager (removes profile from profiles/ directory)\n\tif err := pm.serviceMgr.RemoveProfile(profilemanager.ID(id), androidUsername); err != nil {\n\t\treturn fmt.Errorf(\"failed to remove profile: %w\", err)\n\t}\n\n\t// The account file is this package's, not the ServiceManager's, so it must\n\t// go here. The default profile has a fixed filename, so a recreated one\n\t// would otherwise inherit the deleted profile's email as its login_hint.\n\t// Not fatal: the profile itself is gone.\n\tif err := removeProfileEmail(configPath); err != nil {\n\t\tlog.Warnf(\"failed to remove stored account email for profile %s: %v\", id, err)\n\t}\n\n\tlog.Infof(\"removed profile: %s\", id)\n\treturn nil\n}\n\n// getProfileConfigPath returns the config file path for a profile\n// This is needed for Android-specific path handling (netbird.cfg for default profile)\nfunc (pm *ProfileManager) getProfileConfigPath(id string) (string, error) {\n\tif !profilemanager.IsValidProfileFilenameStem(profilemanager.ID(id)) {","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/android/profile_manager.go#L215-L251","documentation":"RemoveProfile deletes the profile through ServiceManager.RemoveProfile from profiles/. It fails when the id is not a valid filename stem, the profile file cannot be removed (I/O error), or related internal steps fail. The subsequent removal of the stored account email is deliberately best-effort and only logged, never returned, so this error always concerns the profile deletion itself.","triggerScenarios":"RemoveProfile with an invalid id, a profile whose file is locked or unreadable, or an id already removed (repeat removal). The default profile, whose config lives at configDir/netbird.cfg rather than under profiles/, is not managed by this directory path.","commonSituations":"Double-tap on remove where the second call finds nothing, stale list entry after files changed externally, file locked by a concurrent read.","solutions":["Refresh ListProfiles and remove by a current id","Treat a repeat removal of an already-gone profile as success in the UI","Retry on transient I/O errors after checking storage"],"exampleFix":"// before: every tap fires a removal\nremoveBtn.setOnClickListener { pm.RemoveProfile(id) }\n\n// after: ignore the error when the profile is already gone\nif err := pm.RemoveProfile(id); err != nil {\n\tif !profileStillExists(pm, id) { /* already removed: treat as success */ }\n}","handlingStrategy":"validation","validationCode":"// Refresh and confirm the profile still exists before removing\nlist, err := pm.ListProfiles()\nif err == nil && !containsId(list, id) {\n\t// nothing to remove; skip the call\n}","typeGuard":null,"tryCatchPattern":"if err := pm.RemoveProfile(id); err != nil {\n\tlist, lerr := pm.ListProfiles()\n\tif lerr == nil && !containsId(list, id) {\n\t\t// already gone: treat as success\n\t} else {\n\t\t// real removal failure: retry after checking storage\n\t}\n}","preventionTips":["Disable the remove action for an entry once it succeeds","Always remove through ProfileManager so the state file stays consistent","Remember the default profile's config lives at configDir/netbird.cfg, not under profiles/"],"tags":["android","go","profile","filesystem","delete"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}