{"record":{"id":"772e022861f62e33","repo":"rocksdanister/lively","slug":"auth-code-value-cannot-be-null","errorCode":null,"errorMessage":"Auth code value cannot be null.","messagePattern":"Auth code value cannot be null\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Lively/Lively.UI.Shared/ViewModels/Gallery/GalleryLoginViewModel.cs","lineNumber":71,"sourceCode":"\n        private async Task Authenticate(string provider)\n        {\n            if (galleryClient.IsLoggedIn)\n                return;\n\n            IsProcessing = true;\n            Exception exception = null;\n            await Task.Run(async () =>\n            {\n                try\n                {\n                    switch (provider)\n                    {\n                        case \"GOOGLE\":\n                            {\n                                var code = await galleryClient.RequestCodeAsync(\"GOOGLE\");\n                                if (code == null)\n                                    throw new Exception(\"Auth code value cannot be null.\");\n\n                                await galleryClient.AuthenticateGoogleAsync(code);\n                            }\n                            break;\n                        case \"GITHUB\":\n                            {\n                                var code = await galleryClient.RequestCodeAsync(\"GITHUB\");\n                                if (code == null)\n                                    throw new Exception(\"Auth code value cannot be null.\");\n\n                                await galleryClient.AuthenticateGithubAsync(code);\n                            }\n                            break;\n                    }\n                }\n                catch (Exception e)\n                {\n                    exception = e;","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/rocksdanister/lively/blob/c1036feb664960722e34bf4309042c247d6a909d/src/Lively/Lively.UI.Shared/ViewModels/Gallery/GalleryLoginViewModel.cs#L53-L89","documentation":"Thrown in the GalleryLoginViewModel GOOGLE branch when galleryClient.RequestCodeAsync(\"GOOGLE\") returns null — the server did not hand back an OAuth code. Note it throws the base System.Exception, which limits structured handling. Identical logic to the GITHUB branch (error 10).","triggerScenarios":"RequestCodeAsync(\"GOOGLE\") returns null due to a server-side error, network failure, or the gallery's Google OAuth not being configured. The view-model then cannot call AuthenticateGoogleAsync.","commonSituations":"Gallery server down or returning non-2xx; Google provider disabled server-side; client/network issue blocking the code request; regional blocking of the OAuth endpoint.","solutions":["Check network connectivity and that the gallery service is reachable.","Retry RequestCodeAsync once; if still null, surface 'Google sign-in unavailable, try again or use another provider.'","Server-side: verify the Google OAuth app credentials and redirect are configured.","If maintaining the client, throw a typed AuthenticationException instead of base Exception."],"exampleFix":"// before\nvar code = await galleryClient.RequestCodeAsync(\"GOOGLE\");\nif (code == null)\n    throw new Exception(\"Auth code value cannot be null.\");\n\n// after\nvar code = await galleryClient.RequestCodeAsync(\"GOOGLE\");\nif (string.IsNullOrEmpty(code))\n    throw new AuthenticationException(\"Gallery did not return a Google OAuth code; service may be unavailable.\");","handlingStrategy":"retry","validationCode":"string code = null;\nfor (int i = 0; i < 2 && string.IsNullOrEmpty(code); i++)\n    code = await galleryClient.RequestCodeAsync(\"GOOGLE\");\nif (string.IsNullOrEmpty(code)) { ShowError(\"Google sign-in unavailable\"); return; }","typeGuard":"static bool IsValidAuthCode(string code) => !string.IsNullOrWhiteSpace(code);","tryCatchPattern":"try { await galleryClient.AuthenticateGoogleAsync(code); }\ncatch (Exception ex) when (ex.Message.Contains(\"Auth code value cannot be null\"))\n{ ShowError(\"Google OAuth unavailable, retry or use another provider.\"); }","preventionTips":["Retry RequestCodeAsync once for transient nulls.","Offer a fallback provider when one returns null.","Throw a typed AuthenticationException if you maintain the client."],"tags":["auth","oauth","gallery","network","google"],"backgroundTag":null,"analyzedSha":"c1036feb664960722e34bf4309042c247d6a909d","analyzedAt":"2026-08-13T13:03:12.648Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}