git-ecosystem/git-credential-manager · error · InteropException

Failed to erase credentials

Error message

Failed to erase credentials

What it means

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.

Solutions

  1. Inspect the inner exception (GError message) for the concrete daemon failure
  2. Ensure the keyring is unlocked and the daemon is running before deleting
  3. Verify D-Bus session bus availability (echo $DBUS_SESSION_BUS_ADDRESS)
  4. Catch InteropException around Remove and degrade gracefully (log and continue) if deletion is best-effort

Example fix

// before
collection.Remove(service, account); // throws on D-Bus failure
// after
try { collection.Remove(service, account); }
catch (InteropException ex) { Logger.Warn($"Credential erase failed: {ex.InnerException?.Message}"); }
Defensive patterns

Strategy: try-catch

Validate before calling

bool CanReachSecretService() => Environment.GetEnvironmentVariable("DBUS_SESSION_BUS_ADDRESS") != null;

Try / catch

try { collection.Remove(service, account); }
catch (InteropException ex) { Logger.Warn($"Erase failed: {ex.InnerException?.Message}"); /* best-effort delete */ }

Prevention

When it happens

Trigger: Calling Remove(service, account) when the clear D-Bus call fails: keyring locked/unavailable, session bus problems, daemon error while matching items to delete.

Common situations: Deleting from a locked keyring on headless systems; keyring daemon crashed mid-operation; D-Bus session not available in the current environment.

Related errors


AI-assisted analysis of git-ecosystem/git-credential-manager@e8ce762cd0 (2026-09-11). Data as JSON: /api/errors/e78f88bbf3f5769d. Report an issue: GitHub.

Appendix: source

Thrown at src/Core/Interop/Linux/SecretServiceCollection.cs:229

                // Create search query
                attributes = CreateSearchQuery(service, account);

                SecretSchema schema = GetSchema();

                // Erase the secret with the specified key
                bool result = secret_service_clear_sync(
                    secService,
                    ref schema,
                    attributes,
                    IntPtr.Zero,
                    out error);

                if (error != null)
                {
                    int code = error->code;
                    string message = Marshal.PtrToStringAuto(error->message)!;
                    throw new InteropException("Failed to erase credentials", code, new Exception(message));
                }

                return result;
            }
            finally
            {
                if (attributes != null) g_hash_table_destroy(attributes);
                if (error != null) g_error_free(error);
            }
        }

        #endregion

        private unsafe GHashTable* CreateSearchQuery(string service, string account)
        {
            // Build search query
            GHashTable* queryAttrs = g_hash_table_new_full(
                g_str_hash, g_str_equal,

View on GitHub (pinned to e8ce762cd0)