{"record":{"id":"9d8de0012814e0bd","repo":"git-ecosystem/git-credential-manager","slug":"errorsecnosuchkeychain","errorCode":"ErrorSecNoSuchKeychain","errorMessage":"The keychain does not exist.","messagePattern":"The keychain does not exist\\.","errorType":"error_code","errorClass":"InteropException","httpStatus":null,"severity":"error","filePath":"src/Core/Interop/MacOS/Native/SecurityFramework.cs","lineNumber":142,"sourceCode":"        // https://developer.apple.com/documentation/security/1542001-security_framework_result_codes\n        public const int OK = 0;\n        public const int ErrorSecNoSuchKeychain = -25294;\n        public const int ErrorSecInvalidKeychain = -25295;\n        public const int ErrorSecAuthFailed = -25293;\n        public const int ErrorSecDuplicateItem = -25299;\n        public const int ErrorSecItemNotFound = -25300;\n        public const int ErrorSecInteractionNotAllowed = -25308;\n        public const int ErrorSecInteractionRequired = -25315;\n        public const int ErrorSecNoSuchAttr = -25303;\n\n        public static void ThrowIfError(int error, string defaultErrorMessage = \"Unknown error.\")\n        {\n            switch (error)\n            {\n                case OK:\n                    return;\n                case ErrorSecNoSuchKeychain:\n                    throw new InteropException(\"The keychain does not exist.\", error);\n                case ErrorSecInvalidKeychain:\n                    throw new InteropException(\"The keychain is not valid.\", error);\n                case ErrorSecAuthFailed:\n                    throw new InteropException(\"Authorization/Authentication failed.\", error);\n                case ErrorSecDuplicateItem:\n                    throw new InteropException(\"The item already exists.\", error);\n                case ErrorSecItemNotFound:\n                    throw new InteropException(\"The item cannot be found.\", error);\n                case ErrorSecInteractionNotAllowed:\n                    throw new InteropException(\"Interaction with the Security Server is not allowed.\", error);\n                case ErrorSecInteractionRequired:\n                    throw new InteropException(\"User interaction is required.\", error);\n                case ErrorSecNoSuchAttr:\n                    throw new InteropException(\"The attribute does not exist.\", error);\n                default:\n                    throw new InteropException(defaultErrorMessage, error);\n            }\n        }","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/git-ecosystem/git-credential-manager/blob/e8ce762cd04b4100ae637b5fbf39ef9d0a96561e/src/Core/Interop/MacOS/Native/SecurityFramework.cs#L124-L160","documentation":"Thrown by SecurityFramework.ThrowIfError when a Security.framework call returns errSecNoSuchKeychain (-25294): the referenced keychain does not exist. The library maps this OS status code to a descriptive InteropException so callers can catch keychain availability problems with a typed error. Typically surfaced from the legacy SecKeychain* APIs (e.g. SecKeychainFindGenericPassword or SecKeychainAddGenericPassword in AddOrUpdate) operating on the default keychain.","triggerScenarios":"Any MacOSKeychain operation routed through ThrowIfError with OS status -25294 — e.g. AddOrUpdate's SecKeychainFindGenericPassword/SecKeychainAddGenericPassword calls when the default (login) keychain is missing or the default keychain path cannot be resolved.","commonSituations":"Login keychain deleted or never created (fresh/headless accounts), keychain locked-and-removed scenarios, running as a service user (e.g. CI, root, or SSH-only accounts) with no login keychain, or ~/Library/Keychains corrupted/reset.","solutions":["Create/unlock the default keychain: open Keychain Access (or run `security create-keychain` / `security unlock-keychain`) and ensure a login keychain exists for the user","Verify the keychain exists with `security list-keychains` and set a default with `security default-keychain ~/Library/Keychains/login.keychain-db`","If running headless (CI/service user), provision a keychain for that user or switch to a credential store that does not require one (e.g. plaintext store via credential.credentialStore)","Catch the InteropException with code -25294 and fall back to another ICredentialStore"],"exampleFix":"// before\nvar keychain = new MacOSKeychain();\nkeychain.AddOrUpdate(service, account, secret); // throws if login keychain missing\n// after\ntry\n{\n    var keychain = new MacOSKeychain();\n    keychain.AddOrUpdate(service, account, secret);\n}\ncatch (InteropException ex) when (ex.ErrorCode == -25294)\n{\n    // keychain does not exist — fall back to filesystem store\n    var store = new CredentialStoreFactory().CreateDefault();\n}\n","handlingStrategy":"try-catch","validationCode":"using System;\nusing System.Diagnostics;\n\nstatic bool DefaultKeychainExists()\n{\n    var psi = new ProcessStartInfo(\"security\", \"default-keychain\")\n    {\n        RedirectStandardOutput = true, UseShellExecute = false\n    };\n    using var p = Process.Start(psi);\n    p.WaitForExit();\n    return p.ExitCode == 0; // non-zero when no default keychain is set\n}\n\nif (!DefaultKeychainExists())\n{\n    // provision a keychain or switch credential store before calling MacOSKeychain\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    keychain.AddOrUpdate(service, account, secret);\n}\ncatch (InteropException ex) when (ex.ErrorCode == -25294) // errSecNoSuchKeychain\n{\n    // Create/unlock the login keychain or fall back to a non-keychain store\n}\n","preventionTips":["Verify `security default-keychain` succeeds before headless/keychain-dependent runs","In CI, pre-create and unlock a keychain (`security create-keychain`, `security unlock-keychain`) or use a non-keychain credential store","Avoid running as service accounts with no login keychain unless one is provisioned","Catch error code -25294 explicitly and fall back to file/env-based credential stores"],"tags":["macos","keychain","security-framework","interop"],"backgroundTag":"resource-not-found","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"}