Return errors, rather than printing them

This commit is contained in:
2025-05-30 01:08:43 +00:00
parent 74b8261bc8
commit 40f0f35f45
21 changed files with 253 additions and 183 deletions
+9 -4
View File
@@ -1,23 +1,28 @@
package core
import (
"errors"
"github.com/rwinkhart/go-boilerplate/back"
"github.com/rwinkhart/libmutton/crypt"
)
// GetOldEntryData decrypts and returns old entry data (with all required lines present).
func GetOldEntryData(targetLocation string, field int) []string {
func GetOldEntryData(targetLocation string, field int) ([]string, error) {
// ensure targetLocation exists
back.TargetIsFile(targetLocation, true, 2)
// read old entry data
unencryptedEntry := crypt.DecryptFileToSlice(targetLocation)
unencryptedEntry, err := crypt.DecryptFileToSlice(targetLocation)
if err != nil {
return nil, errors.New("unable to decrypt entry: " + err.Error())
}
// return the old entry data with all required lines present
if field > 0 {
return ensureSliceLength(unencryptedEntry, field)
return ensureSliceLength(unencryptedEntry, field), nil
} else {
return unencryptedEntry
return unencryptedEntry, nil
}
}