sync: Replace []error by go.uber.org/multierr
This commit is contained in:
parent
9f49a689fd
commit
b6966d47ce
25 changed files with 380 additions and 348 deletions
|
@ -15,6 +15,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/sync"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
@ -108,14 +110,14 @@ func searchBinaryInGit(edir string) (ret []string) {
|
|||
return
|
||||
}
|
||||
|
||||
func checkExercice(theme *fic.Theme, edir string, dmap *map[int64]*fic.Exercice, exceptions *sync.CheckExceptions) (errs []error) {
|
||||
func checkExercice(theme *fic.Theme, edir string, dmap *map[int64]*fic.Exercice, exceptions *sync.CheckExceptions) (errs error) {
|
||||
e, _, eid, exceptions, _, berrs := sync.BuildExercice(sync.GlobalImporter, theme, path.Join(theme.Path, edir), dmap, nil)
|
||||
errs = append(errs, berrs...)
|
||||
errs = multierr.Append(errs, berrs)
|
||||
|
||||
if e != nil {
|
||||
// Files
|
||||
var files []string
|
||||
var cerrs []error
|
||||
var cerrs error
|
||||
if !skipFileChecks {
|
||||
files, cerrs = sync.CheckExerciceFiles(sync.GlobalImporter, e, exceptions)
|
||||
log.Printf("%d files checked.\n", len(files))
|
||||
|
@ -123,16 +125,16 @@ func checkExercice(theme *fic.Theme, edir string, dmap *map[int64]*fic.Exercice,
|
|||
files, cerrs = sync.CheckExerciceFilesPresence(sync.GlobalImporter, e)
|
||||
log.Printf("%d files presents but not checked (please check digest yourself).\n", len(files))
|
||||
}
|
||||
errs = append(errs, cerrs...)
|
||||
errs = multierr.Append(errs, cerrs)
|
||||
|
||||
// Flags
|
||||
flags, cerrs := sync.CheckExerciceFlags(sync.GlobalImporter, e, files, exceptions)
|
||||
errs = append(errs, cerrs...)
|
||||
errs = multierr.Append(errs, cerrs)
|
||||
log.Printf("%d flags checked.\n", len(flags))
|
||||
|
||||
// Hints
|
||||
hints, cerrs := sync.CheckExerciceHints(sync.GlobalImporter, e, exceptions)
|
||||
errs = append(errs, cerrs...)
|
||||
errs = multierr.Append(errs, cerrs)
|
||||
log.Printf("%d hints checked.\n", len(hints))
|
||||
|
||||
if dmap != nil {
|
||||
|
@ -247,8 +249,9 @@ func main() {
|
|||
theme, exceptions, errs := sync.BuildTheme(sync.GlobalImporter, p)
|
||||
|
||||
if theme != nil && !sync.GlobalImporter.Exists(path.Join(p, "challenge.txt")) && !sync.GlobalImporter.Exists(path.Join(p, "challenge.toml")) {
|
||||
nberr += len(errs)
|
||||
for _, err := range errs {
|
||||
thiserrors := multierr.Errors(errs)
|
||||
nberr += len(thiserrors)
|
||||
for _, err := range thiserrors {
|
||||
log.Println(err)
|
||||
}
|
||||
|
||||
|
@ -264,7 +267,7 @@ func main() {
|
|||
for _, edir := range exercices {
|
||||
ex_exceptions := exceptions.GetFileExceptions(edir)
|
||||
|
||||
for _, err := range checkExercice(theme, edir, &dmap, ex_exceptions) {
|
||||
for _, err := range multierr.Errors(checkExercice(theme, edir, &dmap, ex_exceptions)) {
|
||||
log.Println(err.Error())
|
||||
|
||||
if logMissingResolution {
|
||||
|
@ -294,7 +297,7 @@ func main() {
|
|||
} else {
|
||||
log.Printf("This is not a theme directory, run checks for exercice.\n\n")
|
||||
|
||||
for _, err := range checkExercice(&fic.Theme{}, p, &map[int64]*fic.Exercice{}, nil) {
|
||||
for _, err := range multierr.Errors(checkExercice(&fic.Theme{}, p, &map[int64]*fic.Exercice{}, nil)) {
|
||||
nberr += 1
|
||||
log.Println(err)
|
||||
}
|
||||
|
|
Reference in a new issue