Skip to content

Commit b7da2fc

Browse files
authored
Merge pull request #1290 from felixfontein/empty
Do not crash if an empty YAML file is encrypted
2 parents 4472219 + e422158 commit b7da2fc

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

cmd/sops/codes/codes.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
ConfigFileNotFound int = 61
2222
KeyboardInterrupt int = 85
2323
InvalidTreePathFormat int = 91
24+
NeedAtLeastOneDocument int = 92
2425
NoFileSpecified int = 100
2526
CouldNotRetrieveKey int = 128
2627
NoEncryptionKeyFound int = 111

cmd/sops/encrypt.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func encrypt(opts encryptOpts) (encryptedFile []byte, err error) {
6464
if err != nil {
6565
return nil, common.NewExitError(fmt.Sprintf("Error unmarshalling file: %s", err), codes.CouldNotReadInputFile)
6666
}
67+
if len(branches) < 1 {
68+
return nil, common.NewExitError("File cannot be completely empty, it must contain at least one document", codes.NeedAtLeastOneDocument)
69+
}
6770
if err := ensureNoMetadata(opts, branches[0]); err != nil {
6871
return nil, common.NewExitError(err, codes.FileAlreadyEncrypted)
6972
}

0 commit comments

Comments
 (0)