Skip to content

Commit

Permalink
fine tune error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Mar 28, 2023
1 parent 13def4b commit 68565f0
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions modules/repository/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"context"
"fmt"
"os"
"path"
"path/filepath"
"sort"
"strings"
Expand Down Expand Up @@ -55,26 +54,23 @@ func LoadRepoConfig() {
for i, t := range types {
files, err := options.Dir(t)
if err != nil {
log.Fatal("Failed to get %s files: %v", t, err)
log.Fatal("Failed to list %s files: %v", t, err)
}
customPath := path.Join(setting.CustomPath, "options", t)
isDir, err := util.IsDir(customPath)
if err != nil {
log.Fatal("Failed to get custom %s files: %v", t, err)
}
if isDir {
customPath := filepath.Join(setting.CustomPath, "options", t)
if isDir, err := util.IsDir(customPath); err != nil {
log.Fatal("Failed to check custom %s dir: %v", t, err)
} else if isDir {
customFiles, err := util.StatDir(customPath)
if err != nil {
log.Fatal("Failed to get custom %s files: %v", t, err)
log.Fatal("Failed to list custom %s files: %v", t, err)
}

for _, f := range customFiles {
stat, err := os.Stat(filepath.Join(customPath, f))
if err != nil {
log.Fatal("Failed to stat custom %s files: %v", t, err)
log.Fatal("Failed to stat custom %s file %q: %v", t, f, err)
}
// give end users a chance to hide builtin options if they put an empty file in their custom directory
if stat.Size() == 0 {
// it's good to give end users a chance to hide builtin options if they put an empty file in their custom directory
files = util.SliceRemoveAllFunc(files, func(s string) bool { return strings.EqualFold(s, f) })
} else if !util.SliceContainsString(files, f, true) {
files = append(files, f)
Expand Down

0 comments on commit 68565f0

Please sign in to comment.