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

Failed to store credentials

Error message

Failed to store credentials

What it means

AddOrUpdate calls secret_password_store_sync to write a credential to the Secret Service. If the call returns a GError it throws an InteropException carrying the daemon's error code and message (inner exception), indicating the credential could not be stored.

Solutions

  1. Read the inner exception (GError message) for the daemon's concrete failure reason
  2. Ensure gnome-keyring daemon is running and a default collection exists and is unlocked
  3. Create/unlock the default keyring (seahorse or gnome-keyring-daemon --unlock) before writing
  4. Retry after unlocking; validate that the key/value and attribute strings are non-null and well-formed

Example fix

// before
collection.AddOrUpdate(service, account, secret); // fails if keyring locked
// after
EnsureKeyringUnlocked(); // prompt / gnome-keyring-daemon --unlock
collection.AddOrUpdate(service, account, secret);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(service) || string.IsNullOrEmpty(account) || secret == null)
    throw new ArgumentException("service, account and secret are required before storing");
EnsureKeyringRunningAndUnlocked();

Try / catch

try { collection.AddOrUpdate(service, account, secret); }
catch (InteropException ex) { throw new CredentialStoreException($"Store failed: {ex.InnerException?.Message}", ex); }

Prevention

When it happens

Trigger: Calling AddOrUpdate when the store D-Bus call fails: keyring locked/unavailable, invalid attributes, no default collection, disk full, or daemon rejection.

Common situations: Storing into a locked or missing keyring on a headless server; no default keyring created yet; gnome-keyring not running; schema attribute values containing unsupported characters.

Related errors


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

Appendix: source

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

                SecretSchema schema = GetSchema();

                // Store the secret with the associated attributes
                bool result = secret_service_store_sync(
                    secService,
                    ref schema,
                    attributes,
                    null,
                    fullServiceName, // Use full service name as label
                    secretValue,
                    IntPtr.Zero,
                    out error);

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

                if (!result)
                {
                    throw new InteropException("Failed to store credentials", -1);
                }
            }
            finally
            {
                if (attributes != null) g_hash_table_destroy(attributes);
                if (secretValue != null) secret_value_unref(secretValue);
                if (error != null) g_error_free(error);
            }
        }

        public unsafe bool Remove(string service, string account)
        {
            GHashTable* attributes = null;

View on GitHub (pinned to e8ce762cd0)