{"record":{"id":"285c99a452a34ace","repo":"getsops/sops","slug":"failed-to-encrypt-sops-data-key-with-age-w","errorCode":null,"errorMessage":"failed to encrypt sops data key with age: %w","messagePattern":"failed to encrypt sops data key with age: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"age/keysource.go","lineNumber":182,"sourceCode":"\tif key.parsedRecipient == nil {\n\t\tparsedRecipient, err := parseRecipient(key.Recipient)\n\t\tif err != nil {\n\t\t\tlog.WithField(\"recipient\", key.parsedRecipient).Info(\"Encryption failed\")\n\t\t\treturn err\n\t\t}\n\t\tkey.parsedRecipient = parsedRecipient\n\t}\n\n\tvar buffer bytes.Buffer\n\taw := armor.NewWriter(&buffer)\n\tw, err := age.Encrypt(aw, key.parsedRecipient)\n\tif err != nil {\n\t\tlog.WithField(\"recipient\", key.parsedRecipient).Info(\"Encryption failed\")\n\t\treturn fmt.Errorf(\"failed to create writer for encrypting sops data key with age: %w\", err)\n\t}\n\tif _, err := w.Write(dataKey); err != nil {\n\t\tlog.WithField(\"recipient\", key.parsedRecipient).Info(\"Encryption failed\")\n\t\treturn fmt.Errorf(\"failed to encrypt sops data key with age: %w\", err)\n\t}\n\tif err := w.Close(); err != nil {\n\t\tlog.WithField(\"recipient\", key.parsedRecipient).Info(\"Encryption failed\")\n\t\treturn fmt.Errorf(\"failed to close writer for encrypting sops data key with age: %w\", err)\n\t}\n\tif err := aw.Close(); err != nil {\n\t\tlog.WithField(\"recipient\", key.parsedRecipient).Info(\"Encryption failed\")\n\t\treturn fmt.Errorf(\"failed to close armored writer: %w\", err)\n\t}\n\n\tkey.SetEncryptedDataKey(buffer.Bytes())\n\tlog.WithField(\"recipient\", key.parsedRecipient).Info(\"Encryption succeeded\")\n\treturn nil\n}\n\n// EncryptIfNeeded encrypts the provided SOPS data key, if it has not been\n// encrypted yet.\nfunc (key *MasterKey) EncryptIfNeeded(dataKey []byte) error {","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/age/keysource.go#L164-L200","documentation":"Error \"failed to encrypt sops data key with age: %w\" thrown in getsops/sops.","triggerScenarios":"Thrown at age/keysource.go:182 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"13442bb98183887d7a9ac09ec8ab0564673a59d8","analyzedAt":"2026-09-01T03:53:00.447Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}