{"record":{"id":"e78f88bbf3f5769d","repo":"git-ecosystem/git-credential-manager","slug":"failed-to-erase-credentials","errorCode":null,"errorMessage":"Failed to erase credentials","messagePattern":"Failed to erase credentials","errorType":"exception","errorClass":"InteropException","httpStatus":null,"severity":"error","filePath":"src/Core/Interop/Linux/SecretServiceCollection.cs","lineNumber":229,"sourceCode":"\r\n                // Create search query\r\n                attributes = CreateSearchQuery(service, account);\r\n\r\n                SecretSchema schema = GetSchema();\r\n\r\n                // Erase the secret with the specified key\r\n                bool result = secret_service_clear_sync(\r\n                    secService,\r\n                    ref schema,\r\n                    attributes,\r\n                    IntPtr.Zero,\r\n                    out error);\r\n\r\n                if (error != null)\r\n                {\r\n                    int code = error->code;\r\n                    string message = Marshal.PtrToStringAuto(error->message)!;\r\n                    throw new InteropException(\"Failed to erase credentials\", code, new Exception(message));\r\n                }\r\n\r\n                return result;\r\n            }\r\n            finally\r\n            {\r\n                if (attributes != null) g_hash_table_destroy(attributes);\r\n                if (error != null) g_error_free(error);\r\n            }\r\n        }\r\n\r\n        #endregion\r\n\r\n        private unsafe GHashTable* CreateSearchQuery(string service, string account)\r\n        {\r\n            // Build search query\r\n            GHashTable* queryAttrs = g_hash_table_new_full(\r\n                g_str_hash, g_str_equal,\r","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Interop/Linux/SecretServiceCollection.cs#L211-L247","documentation":"Remove calls secret_password_clear_sync to erase a credential from the Secret Service. If the call returns a GError it throws an InteropException with the daemon's code and message (as the inner exception), meaning the credential deletion did not complete.","triggerScenarios":"Calling Remove(service, account) when the clear D-Bus call fails: keyring locked/unavailable, session bus problems, daemon error while matching items to delete.","commonSituations":"Deleting from a locked keyring on headless systems; keyring daemon crashed mid-operation; D-Bus session not available in the current environment.","solutions":["Inspect the inner exception (GError message) for the concrete daemon failure","Ensure the keyring is unlocked and the daemon is running before deleting","Verify D-Bus session bus availability (echo $DBUS_SESSION_BUS_ADDRESS)","Catch InteropException around Remove and degrade gracefully (log and continue) if deletion is best-effort"],"exampleFix":"// before\ncollection.Remove(service, account); // throws on D-Bus failure\n// after\ntry { collection.Remove(service, account); }\ncatch (InteropException ex) { Logger.Warn($\"Credential erase failed: {ex.InnerException?.Message}\"); }","handlingStrategy":"try-catch","validationCode":"bool CanReachSecretService() => Environment.GetEnvironmentVariable(\"DBUS_SESSION_BUS_ADDRESS\") != null;","typeGuard":null,"tryCatchPattern":"try { collection.Remove(service, account); }\ncatch (InteropException ex) { Logger.Warn($\"Erase failed: {ex.InnerException?.Message}\"); /* best-effort delete */ }","preventionTips":["Ensure the keyring is unlocked before delete operations","Treat deletion as best-effort and log rather than crash when erasing cached credentials","Verify D-Bus session availability in deployment environments","Test remove flows on the actual target distros/keyring versions"],"tags":["linux","keyring","credentials","dbus"],"backgroundTag":"database-write-failed","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"}