{"record":{"id":"d46636cb12e6474a","repo":"netbirdio/netbird","slug":"switch-profile-failed-w","errorCode":null,"errorMessage":"switch profile failed: %w","messagePattern":"switch profile failed: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"client/cmd/login.go","lineNumber":309,"sourceCode":"// re-resolving the handle.\nfunc switchProfile(ctx context.Context, handle string, username string) (profilemanager.ID, error) {\n\tconn, err := DialClientGRPCServer(ctx, daemonAddr)\n\tif err != nil {\n\t\t//nolint\n\t\treturn \"\", fmt.Errorf(\"failed to connect to daemon error: %v\\n\"+\n\t\t\t\"If the daemon is not running please run: \"+\n\t\t\t\"\\nnetbird service install \\nnetbird service start\\n\", err)\n\t}\n\tdefer conn.Close()\n\n\tclient := proto.NewDaemonServiceClient(conn)\n\n\tresp, err := client.SwitchProfile(ctx, &proto.SwitchProfileRequest{\n\t\tProfileName: &handle,\n\t\tUsername:    &username,\n\t})\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"switch profile failed: %w\", err)\n\t}\n\n\treturn profilemanager.ID(resp.Id), nil\n}\n\nfunc doForegroundLogin(ctx context.Context, cmd *cobra.Command, setupKey string, activeProf *profilemanager.Profile) error {\n\n\terr := handleRebrand(cmd)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// update host's static platform and system information\n\tsystem.UpdateStaticInfoAsync()\n\n\tconfigFilePath, err := activeProf.FilePath()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get active profile file path: %v\", err)","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/netbirdio/netbird/blob/93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c/client/cmd/login.go#L291-L327","documentation":"The daemon answered the SwitchProfile RPC itself with a gRPC error: no profile matched the supplied ProfileName+Username combination, the unique-ID prefix was ambiguous, or the daemon failed while loading the requested profile. Unlike its siblings, this uses %w, so the gRPC status is unwrappable with errors.As/errors.Is for programmatic handling.","triggerScenarios":"Passing a profile name that does not exist (typo, deleted profile); passing a name that belongs to a different username when the username filter is set; a short profile ID that matches multiple profiles; daemon-side load error on a corrupted profile file.","commonSituations":"Scripts pinning a profile name that was renamed; Multiple users on one host with same-named profiles but --username omitted; Copy-pasted truncated IDs from 'netbird profile list'","solutions":["Run 'netbird profile list' and pass the exact name or the full ID","When names collide, include the correct --username so the daemon can disambiguate","If the ID prefix is ambiguous, use the complete ID","For daemon-side load errors, inspect the daemon logs for the profile file it failed to parse"],"exampleFix":"# before\n$ netbird login --profile-name corp\nError: switch profile failed: rpc error: code = NotFound\n\n# after: list, then use the full name or ID\n$ netbird profile list\nID            NAME      USER\ncx3f corp-fmt  alice\n$ netbird login --profile-name corp-fmt\n# or: netbird login --profile-name cx3f9a12...","handlingStrategy":"validation","validationCode":"// Exact-match pre-check avoids NotFound and ambiguity before the RPC\nprofiles, _ := pm.GetProfiles()\nmatches := 0\nfor _, p := range profiles {\n    if p.Name == handle || strings.HasPrefix(string(p.ID), handle) {\n        matches++\n    }\n}\nif matches == 0 {\n    return fmt.Errorf(\"%q matches no profile\", handle)\n}\nif matches > 1 {\n    return fmt.Errorf(\"%q is ambiguous; use the full profile ID\", handle)\n}","typeGuard":null,"tryCatchPattern":"// %w is used, so the gRPC status survives wrapping\nif _, err := client.SwitchProfile(ctx, req); err != nil {\n    if status.Code(err) == codes.NotFound {\n        return fmt.Errorf(\"profile %q not found for user %q: %w\", handle, username, err)\n    }\n    return fmt.Errorf(\"switch profile failed: %w\", err)\n}","preventionTips":["Always quote profile names in scripts to prevent shell splitting","Prefer full IDs over prefixes in automation","Keep usernames aligned with profile ownership when multiple humans share a workstation"],"tags":["profile","grpc","not-found","cli","netbird"],"backgroundTag":null,"analyzedSha":"93e97f4bf1ad715072dcb3fb6cdb1763431b5a9c","analyzedAt":"2026-08-16T03:09:19.136Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}