{"record":{"id":"4923691b0eff68ca","repo":"plandex-ai/plandex","slug":"auth-current-userid-is-empty","errorCode":null,"errorMessage":"auth.Current.UserId is empty","messagePattern":"auth\\.Current\\.UserId is empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/custom_models.go","lineNumber":333,"sourceCode":"\t\t\t\tcolor.New(color.Bold, term.ColorHiRed).Sprint(modelPack.Name)))\n\t\t}\n\t}\n\n\tif updated.Len()+added.Len()+deleted.Len() == 0 {\n\t\treturn false\n\t}\n\n\tfmt.Print(added.String())\n\tfmt.Print(updated.String())\n\tfmt.Print(deleted.String())\n\n\treturn true\n}\n\nfunc SyncCustomModels() error {\n\tuserId := auth.Current.UserId\n\tif userId == \"\" {\n\t\treturn fmt.Errorf(\"auth.Current.UserId is empty\")\n\t}\n\n\tserverModelsInput, err := GetServerModelsInput()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting server models input: %v\", err)\n\t}\n\n\tMustSyncCustomModels(GetCustomModelsPath(userId), serverModelsInput)\n\n\treturn nil\n}\n","sourceCodeStart":315,"sourceCodeEnd":345,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/custom_models.go#L315-L345","documentation":"SyncCustomModels reads auth.Current.UserId to build the account-scoped custom models path. This error means the CLI attempted to sync custom models before authentication state was populated — auth.Current has no logged-in user, so the target account directory cannot be determined. It is a fail-fast guard, not a network failure.","triggerScenarios":"Calling SyncCustomModels when no user is logged in (auth.Current is zero-value), when auth session loading failed or was skipped, or when the caller invokes it from a non-authenticated context such as during onboarding or in tests without auth setup.","commonSituations":"Running a command that syncs models before `plandex auth` / login; expired auth file removed so Current is empty; automation scripts calling the library directly without initializing auth.","solutions":["Log in first (plandex auth or the equivalent login command) so auth.Current.UserId is populated.","Verify the auth session file exists under ~/.plandex and is not corrupt; re-authenticate if it is.","Ensure any code calling SyncCustomModels does so only after auth initialization completes.","If auth is loaded but UserId is still empty, re-install/upgrade the CLI to fix auth-state loading."],"exampleFix":"// before\nlib.SyncCustomModels()  # panics into 'auth.Current.UserId is empty'\n// after\nif auth.Current != nil && auth.Current.UserId != \"\" {\n  lib.SyncCustomModels()\n}","handlingStrategy":"validation","validationCode":"// Check auth state before calling SyncCustomModels\nif auth.Current == nil || auth.Current.UserId == \"\" {\n    term.Error(\"Not logged in; run the auth/login command first\")\n    return\n}\nerr := lib.SyncCustomModels()","typeGuard":"func isLoggedIn() bool {\n    return auth.Current != nil && auth.Current.UserId != \"\"\n}","tryCatchPattern":"// Go: guard rather than catch; if you must call unconditionally:\nif err := lib.SyncCustomModels(); err != nil {\n    if strings.Contains(err.Error(), \"auth.Current.UserId is empty\") {\n        term.Error(\"Please log in first\")\n        return\n    }\n    return err\n}","preventionTips":["Always complete login before commands that sync models.","In scripts/automation, check auth state explicitly before library calls.","Re-authenticate if the auth session file was deleted or expired.","Don't initialize auth concurrently; wait for auth loading to finish before syncing."],"tags":["go","auth","session","custom-models"],"backgroundTag":"not-authenticated","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}