{"record":{"id":"62c31b7beccc49e2","repo":"netbirdio/netbird","slug":"failed-to-get-active-profile-w","errorCode":null,"errorMessage":"failed to get active profile: %w","messagePattern":"failed to get active profile: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"client/android/profile_manager.go","lineNumber":118,"sourceCode":"\tfor _, p := range internalProfiles {\n\t\tprofiles = append(profiles, &Profile{\n\t\t\tID:       p.ID.String(),\n\t\t\tName:     p.Name,\n\t\t\tEmail:    pm.profileEmail(p.ID.String()),\n\t\t\tIsActive: p.IsActive,\n\t\t})\n\t}\n\n\treturn &ProfileArray{items: profiles}, nil\n}\n\n// GetActiveProfile returns the currently active profile name\nfunc (pm *ProfileManager) GetActiveProfile() (*Profile, error) {\n\t// Use ServiceManager to stay consistent with ListProfiles\n\t// ServiceManager uses active_profile.json\n\tactiveState, err := pm.serviceMgr.GetActiveProfileState()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get active profile: %w\", err)\n\t}\n\n\t// ActiveProfileState only stores the ID (and username), not the display\n\t// name. Resolve the ID to the full profile so callers get the real Name.\n\tprof, err := pm.serviceMgr.ResolveProfile(activeState.ID.String(), androidUsername)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to resolve active profile %q: %w\", activeState.ID, err)\n\t}\n\treturn &Profile{\n\t\tID:       prof.ID.String(),\n\t\tName:     prof.Name,\n\t\tEmail:    pm.profileEmail(prof.ID.String()),\n\t\tIsActive: true,\n\t}, nil\n}\n\n// profileEmail returns the account email recorded for a profile. Display-only, so\n// an unresolvable path degrades to \"\" rather than an error.","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/android/profile_manager.go#L100-L136","documentation":"GetActiveProfile reads configDir/active_profile.json through ServiceManager.GetActiveProfileState. This error means that file could not be turned into state: it is missing (no profile was ever activated — the normal fresh-install condition), unreadable, or malformed JSON. The underlying read/parse error is wrapped.","triggerScenarios":"GetActiveProfile (directly or via GetActiveConfigPath/GetActiveStateFilePath) is called before any SwitchProfile, AddProfile, or first-run login created active_profile.json; or the file is corrupt after an interrupted write or partial data clear.","commonSituations":"First app launch, app data cleared, backup restored only some files, file truncated by a disk-full write.","solutions":["On fresh installs, establish a profile first: AddProfile/SwitchProfile or a first login writes active_profile.json","If the file is corrupt, delete active_profile.json and switch to an existing profile to regenerate it","Treat the error as 'no active profile yet' in the UI rather than a hard failure"],"exampleFix":"// before: assume an active profile always exists\np, err := pm.GetActiveProfile() // fails on fresh install\n\n// after: handle the no-active-profile case\np, err := pm.GetActiveProfile()\nif err != nil {\n\t_ = pm.SwitchProfile(\"default\") // or prompt the user to log in\n\tp, err = pm.GetActiveProfile()\n}","handlingStrategy":"fallback","validationCode":"// Check the state file before assuming an active profile exists\nif _, err := os.Stat(filepath.Join(configDir, \"active_profile.json\")); os.IsNotExist(err) {\n\t// fresh install: use the default profile instead of calling GetActiveProfile\n}","typeGuard":null,"tryCatchPattern":"p, err := pm.GetActiveProfile()\nif err != nil {\n\t// no usable active state: fall back to default and/or prompt first login\n\t_ = pm.SwitchProfile(\"default\")\n\tp, err = pm.GetActiveProfile()\n}","preventionTips":["Establish a profile (AddProfile/SwitchProfile or first login) before any GetActive* call","Treat a missing active_profile.json as a normal first-run state, not an error","Avoid partial data restores that keep active_profile.json but drop profile files"],"tags":["android","go","profile","filesystem","first-run"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}