{"record":{"id":"87c357980b37fc6d","repo":"getsops/sops","slug":"failed-to-close-armored-writer-w","errorCode":null,"errorMessage":"failed to close armored writer: %w","messagePattern":"failed to close armored writer: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"age/keysource.go","lineNumber":190,"sourceCode":"\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 {\n\tif key.EncryptedKey == \"\" {\n\t\treturn key.Encrypt(dataKey)\n\t}\n\treturn nil\n}\n\n// EncryptedDataKey returns the encrypted SOPS data key this master key holds.\nfunc (key *MasterKey) EncryptedDataKey() []byte {","sourceCodeStart":172,"sourceCodeEnd":208,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/age/keysource.go#L172-L208","documentation":"Error \"failed to close armored writer: %w\" thrown in getsops/sops.","triggerScenarios":"Thrown at age/keysource.go:190 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"}