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 -7
View File
@@ -3,31 +3,31 @@
package synccommon
import (
"errors"
"io/fs"
"os"
"path/filepath"
"github.com/rwinkhart/go-boilerplate/back"
"github.com/rwinkhart/libmutton/global"
)
// WalkEntryDir walks the entry directory and returns lists of all files and directories found (two separate lists).
// Regardless of platform, all paths are stored with forward slashes (UNIX-style).
func WalkEntryDir() ([]string, []string) {
func WalkEntryDir() ([]string, []string, error) {
// define file/directory containing slices so that they may be accessed by the anonymous WalkDir function
var fileList []string
var dirList []string
// walk entry directory
_ = filepath.WalkDir(global.EntryRoot,
err := filepath.WalkDir(global.EntryRoot,
func(fullPath string, entry fs.DirEntry, err error) error {
// check for errors encountered while walking directory
if err != nil {
if os.IsNotExist(err) {
back.PrintError("The entry directory does not exist - Initialize libmutton to create it", back.ErrorOther, true)
return errors.New("entry directory does not exist; initialize libmutton to create it")
} else {
back.PrintError("An unexpected error occurred while generating the entry list: "+err.Error(), back.ErrorOther, true)
return errors.New("an unexpected error occurred while generating the entry list: " + err.Error())
}
}
@@ -43,6 +43,8 @@ func WalkEntryDir() ([]string, []string) {
return nil
})
return fileList, dirList
if err != nil {
return nil, nil, err
}
return fileList, dirList, nil
}