{"record":{"id":"51005d320850778e","repo":"git-ecosystem/git-credential-manager","slug":"remoteuri-must-be-defined-to-generate-bitbucket-dc-51005d","errorCode":null,"errorMessage":"RemoteUri must be defined to generate Bitbucket DC OAuth2 endpoint Urls","messagePattern":"RemoteUri must be defined to generate Bitbucket DC OAuth2 endpoint Urls","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Atlassian.Bitbucket/DataCenter/BitbucketRestApi.cs","lineNumber":152,"sourceCode":"\n            return authenticationMethods;\n        }\n\n        public void Dispose()\n        {\n            _httpClient?.Dispose();\n        }\n\n        private HttpClient HttpClient => _httpClient ??= _context.HttpClientFactory.CreateClient();\n\n        private Uri ApiUri\n        {\n            get\n            {\n                var remoteUri = _context.Settings?.RemoteUri;\n                if (remoteUri == null)\n                {\n                    throw new ArgumentException(\"RemoteUri must be defined to generate Bitbucket DC OAuth2 endpoint Urls\");\n                }\n\n                return new Uri(BitbucketHelper.GetBaseUri(remoteUri) + \"/rest/\");\n            }\n        }\n    }\n}\n","sourceCodeStart":134,"sourceCodeEnd":160,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Atlassian.Bitbucket/DataCenter/BitbucketRestApi.cs#L134-L160","documentation":"BitbucketRestApi's BaseUri property derives the REST API root from _context.Settings?.RemoteUri. When RemoteUri is null it throws the same ArgumentException because OAuth2 endpoint/REST URLs cannot be generated without a server URL.","triggerScenarios":"Constructing or using BitbucketRestApi for a Bitbucket DC host when Context.Settings is null or Settings.RemoteUri is null — e.g. API calls made before remote URL settings were populated by the credential query.","commonSituations":"Programmatic use of GCM's Bitbucket API classes with a context lacking settings; credential operations triggered outside a normal git remote query; tests/tools creating the context without RemoteUri.","solutions":["Populate the settings with a valid remote URI before using BitbucketRestApi.","Invoke the flow through git so the helper receives host/path and Settings.RemoteUri is set.","Guard callers: check Context.Settings?.RemoteUri != null before constructing/restApi calls."],"exampleFix":"// before\nvar api = new BitbucketRestApi(context); // Settings.RemoteUri == null -> throws\n// after\nif (context.Settings?.RemoteUri == null) throw new InvalidOperationException(\"RemoteUri required\");\nvar api = new BitbucketRestApi(context);","handlingStrategy":"validation","validationCode":"if (context.Settings?.RemoteUri == null) throw new InvalidOperationException(\"RemoteUri required before using BitbucketRestApi\");","typeGuard":"bool remoteReady = !string.IsNullOrWhiteSpace(context?.Settings?.RemoteUri?.ToString());","tryCatchPattern":"try { var root = restApi.BaseUri; } catch (ArgumentException ex) when (ex.Message.Contains(\"RemoteUri\")) { /* populate settings or abort */ }","preventionTips":["Construct BitbucketRestApi only after the credential query has populated settings","Assert RemoteUri non-null in unit tests and integration harnesses","Route users through standard git operations rather than direct API construction"],"tags":["bitbucket","rest-api","configuration","git-credential-manager"],"backgroundTag":"missing-required-argument","analyzedSha":"e8ce762cd04b4100ae637b5fbf39ef9d0a96561e","analyzedAt":"2026-09-11T17:15:08.753Z","contentChangedAt":"2026-09-11T17:15:08.753Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}