Use fmt.Errorf

This commit is contained in:
nemunaire 2020-04-15 07:39:38 +02:00
commit adb424ea03
11 changed files with 50 additions and 60 deletions

View file

@ -1,7 +1,6 @@
package sync
import (
"errors"
"fmt"
"path"
"strconv"
@ -71,13 +70,13 @@ func buildDependancyMap(i Importer, theme fic.Theme) (dmap map[int64]fic.Exercic
func parseExerciceDirname(edir string) (eid int, ename string, err error) {
edir_splt := strings.SplitN(edir, "-", 2)
if len(edir_splt) != 2 {
err = errors.New(fmt.Sprintf("%q is not a valid exercice directory: missing id prefix", edir))
err = fmt.Errorf("%q is not a valid exercice directory: missing id prefix", edir)
return
}
eid, err = strconv.Atoi(edir_splt[0])
if err != nil {
err = errors.New(fmt.Sprintf("%q: invalid exercice identifier: %s", edir, err))
err = fmt.Errorf("%q: invalid exercice identifier: %s", edir, err)
return
}
@ -270,7 +269,7 @@ func ApiListRemoteExercices(ps httprouter.Params, _ []byte) (interface{}, error)
if theme != nil {
return GetExercices(GlobalImporter, *theme)
} else {
return nil, errors.New(fmt.Sprintf("%q", errs))
return nil, fmt.Errorf("%q", errs)
}
}
@ -282,9 +281,9 @@ func ApiGetRemoteExercice(ps httprouter.Params, _ []byte) (interface{}, error) {
if exercice != nil {
return exercice, nil
} else {
return exercice, errors.New(fmt.Sprintf("%q", errs))
return exercice, fmt.Errorf("%q", errs)
}
} else {
return nil, errors.New(fmt.Sprintf("%q", errs))
return nil, fmt.Errorf("%q", errs)
}
}