Use fmt.Errorf
This commit is contained in:
parent
45069d4fbb
commit
adb424ea03
@ -138,7 +138,7 @@ func loadFlags(n func () ([]fic.Flag, error)) (interface{}, error) {
|
|||||||
ret = append(ret, m)
|
ret = append(ret, m)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("Flag type %T not implemented for this flag.", f))
|
return nil, fmt.Errorf("Flag type %T not implemented for this flag.", f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"srs.epita.fr/fic-server/admin/sync"
|
"srs.epita.fr/fic-server/admin/sync"
|
||||||
@ -77,7 +76,7 @@ func genFileList(in []fic.EFile, e error) (out []APIFile, err error) {
|
|||||||
|
|
||||||
g.Depends = append(g.Depends, m)
|
g.Depends = append(g.Depends, m)
|
||||||
} else {
|
} else {
|
||||||
err = errors.New(fmt.Sprintf("Unknown type %T to handle file dependancy", k))
|
err = fmt.Errorf("Unknown type %T to handle file dependancy", k)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@ package sync
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -162,12 +161,12 @@ func ApiGetRemoteExerciceFiles(ps httprouter.Params, _ []byte) (interface{}, err
|
|||||||
}
|
}
|
||||||
return ret, nil
|
return ret, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
return nil, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
return nil, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
return nil, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"crypto"
|
"crypto"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -150,12 +149,12 @@ func ApiGetRemoteExerciceHints(ps httprouter.Params, _ []byte) (interface{}, err
|
|||||||
if hints != nil {
|
if hints != nil {
|
||||||
return hints, nil
|
return hints, nil
|
||||||
} else {
|
} else {
|
||||||
return hints, errors.New(fmt.Sprintf("%q", errs))
|
return hints, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return exercice, errors.New(fmt.Sprintf("%q", errs))
|
return exercice, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
return nil, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package sync
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"path"
|
"path"
|
||||||
@ -392,7 +391,6 @@ func ExerciceFlagsMap(i Importer, exercice fic.Exercice) (kmap map[int64]fic.Fla
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// SyncExerciceFlags imports all kind of flags for the given challenge.
|
// SyncExerciceFlags imports all kind of flags for the given challenge.
|
||||||
func SyncExerciceFlags(i Importer, exercice fic.Exercice) (kmap map[int64]fic.Flag, errs []string) {
|
func SyncExerciceFlags(i Importer, exercice fic.Exercice) (kmap map[int64]fic.Flag, errs []string) {
|
||||||
if _, err := exercice.WipeFlags(); err != nil {
|
if _, err := exercice.WipeFlags(); err != nil {
|
||||||
@ -456,12 +454,12 @@ func ApiGetRemoteExerciceFlags(ps httprouter.Params, _ []byte) (interface{}, err
|
|||||||
if flags != nil {
|
if flags != nil {
|
||||||
return flags, nil
|
return flags, nil
|
||||||
} else {
|
} else {
|
||||||
return flags, errors.New(fmt.Sprintf("%q", errs))
|
return flags, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return exercice, errors.New(fmt.Sprintf("%q", errs))
|
return exercice, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
return nil, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package sync
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strconv"
|
"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) {
|
func parseExerciceDirname(edir string) (eid int, ename string, err error) {
|
||||||
edir_splt := strings.SplitN(edir, "-", 2)
|
edir_splt := strings.SplitN(edir, "-", 2)
|
||||||
if len(edir_splt) != 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
eid, err = strconv.Atoi(edir_splt[0])
|
eid, err = strconv.Atoi(edir_splt[0])
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,7 +269,7 @@ func ApiListRemoteExercices(ps httprouter.Params, _ []byte) (interface{}, error)
|
|||||||
if theme != nil {
|
if theme != nil {
|
||||||
return GetExercices(GlobalImporter, *theme)
|
return GetExercices(GlobalImporter, *theme)
|
||||||
} else {
|
} 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 {
|
if exercice != nil {
|
||||||
return exercice, nil
|
return exercice, nil
|
||||||
} else {
|
} else {
|
||||||
return exercice, errors.New(fmt.Sprintf("%q", errs))
|
return exercice, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return nil, errors.New(fmt.Sprintf("%q", errs))
|
return nil, fmt.Errorf("%q", errs)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
@ -75,7 +74,7 @@ func getFileSize(i Importer, URI string) (size int64, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return size, errors.New(fmt.Sprintf("%q: no such file or directory", URI))
|
return size, fmt.Errorf("%q: no such file or directory", URI)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFile helps to manage huge file transfert by concatenating splitted (with split(1)) files.
|
// getFile helps to manage huge file transfert by concatenating splitted (with split(1)) files.
|
||||||
@ -110,7 +109,7 @@ func getFile(i Importer, URI string, writer *bufio.Writer) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return errors.New(fmt.Sprintf("%q: no such file or directory", URI))
|
return fmt.Errorf("%q: no such file or directory", URI)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getFileContent retrieves the content of the given text file.
|
// getFileContent retrieves the content of the given text file.
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package sync
|
package sync
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/jpeg"
|
"image/jpeg"
|
||||||
@ -217,7 +216,7 @@ func ApiListRemoteThemes(_ httprouter.Params, _ []byte) (interface{}, error) {
|
|||||||
func ApiGetRemoteTheme(ps httprouter.Params, _ []byte) (interface{}, error) {
|
func ApiGetRemoteTheme(ps httprouter.Params, _ []byte) (interface{}, error) {
|
||||||
r, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
|
r, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return r, errors.New(fmt.Sprintf("%q", errs))
|
return r, fmt.Errorf("%q", errs)
|
||||||
} else {
|
} else {
|
||||||
return r, nil
|
return r, nil
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
@ -103,7 +102,7 @@ func genTeamIssuesFile(team fic.Team) error {
|
|||||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dirPath, 0777)
|
os.MkdirAll(dirPath, 0777)
|
||||||
} else if !s.IsDir() {
|
} else if !s.IsDir() {
|
||||||
return errors.New(fmt.Sprintf("%s is not a directory", dirPath))
|
return fmt.Errorf("%s is not a directory", dirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if my, err := team.MyIssueFile(); err != nil {
|
if my, err := team.MyIssueFile(); err != nil {
|
||||||
@ -124,7 +123,7 @@ func genTeamMyFile(team *fic.Team) error {
|
|||||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dirPath, 0777)
|
os.MkdirAll(dirPath, 0777)
|
||||||
} else if !s.IsDir() {
|
} else if !s.IsDir() {
|
||||||
return errors.New(fmt.Sprintf("%s is not a directory", dirPath))
|
return fmt.Errorf("%s is not a directory", dirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if my, err := fic.MyJSONTeam(team, true); err != nil {
|
if my, err := fic.MyJSONTeam(team, true); err != nil {
|
||||||
@ -156,7 +155,7 @@ func genMyPublicFile() error {
|
|||||||
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
if s, err := os.Stat(dirPath); os.IsNotExist(err) {
|
||||||
os.MkdirAll(dirPath, 0777)
|
os.MkdirAll(dirPath, 0777)
|
||||||
} else if !s.IsDir() {
|
} else if !s.IsDir() {
|
||||||
return errors.New(fmt.Sprintf("%s is not a directory", dirPath))
|
return fmt.Errorf("%s is not a directory", dirPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
if my, err := fic.MyJSONTeam(nil, true); err != nil {
|
if my, err := fic.MyJSONTeam(nil, true); err != nil {
|
||||||
|
@ -210,7 +210,7 @@ func (k FlagKey) AddDepend(j Flag) (err error) {
|
|||||||
} else if d, ok := j.(MCQ); ok {
|
} else if d, ok := j.(MCQ); ok {
|
||||||
_, err = DBExec("INSERT INTO exercice_flags_omcq_deps (id_flag, id_mcq_dep) VALUES (?, ?)", k.Id, d.Id)
|
_, err = DBExec("INSERT INTO exercice_flags_omcq_deps (id_flag, id_mcq_dep) VALUES (?, ?)", k.Id, d.Id)
|
||||||
} else {
|
} else {
|
||||||
err = errors.New(fmt.Sprintf("Dependancy type for key (%T) not implemented for this flag.", j))
|
err = fmt.Errorf("Dependancy type for key (%T) not implemented for this flag.", j)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package fic
|
package fic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
@ -138,7 +137,7 @@ func (h EHint) AddDepend(f Flag) (err error) {
|
|||||||
} else if d, ok := f.(MCQ); ok {
|
} else if d, ok := f.(MCQ); ok {
|
||||||
_, err = DBExec("INSERT INTO exercice_hints_omcq_deps (id_hint, id_mcq_dep) VALUES (?, ?)", h.Id, d.Id)
|
_, err = DBExec("INSERT INTO exercice_hints_omcq_deps (id_hint, id_mcq_dep) VALUES (?, ?)", h.Id, d.Id)
|
||||||
} else {
|
} else {
|
||||||
err = errors.New(fmt.Sprintf("Dependancy type for key (%T) not implemented for this flag.", f))
|
err = fmt.Errorf("Dependancy type for key (%T) not implemented for this flag.", f)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user