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
|
|
@ -8,6 +8,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/generation"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
|
@ -49,7 +51,7 @@ func SpeedySyncDeep(i Importer) (errs SyncReport) {
|
|||
|
||||
errs.DateStart = startTime
|
||||
exceptions, sterrs := SyncThemes(i)
|
||||
for _, sterr := range sterrs {
|
||||
for _, sterr := range multierr.Errors(sterrs) {
|
||||
errs.ThemesSync = append(errs.ThemesSync, sterr.Error())
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +62,7 @@ func SpeedySyncDeep(i Importer) (errs SyncReport) {
|
|||
for tid, theme := range themes {
|
||||
DeepSyncProgress = 3 + uint8(tid)*themeStep
|
||||
ex_exceptions, seerrs := SyncExercices(i, theme, exceptions[theme.Path])
|
||||
for _, seerr := range seerrs {
|
||||
for _, seerr := range multierr.Errors(seerrs) {
|
||||
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], seerr.Error())
|
||||
}
|
||||
|
||||
|
|
@ -74,13 +76,13 @@ func SpeedySyncDeep(i Importer) (errs SyncReport) {
|
|||
|
||||
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
|
||||
flagsBindings, ferrs := SyncExerciceFlags(i, exercice, ex_exceptions[eid])
|
||||
for _, ferr := range ferrs {
|
||||
for _, ferr := range multierr.Errors(ferrs) {
|
||||
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], ferr.Error())
|
||||
}
|
||||
|
||||
DeepSyncProgress += exerciceStep / 2
|
||||
_, herrs := SyncExerciceHints(i, exercice, flagsBindings, ex_exceptions[eid])
|
||||
for _, herr := range herrs {
|
||||
for _, herr := range multierr.Errors(herrs) {
|
||||
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], herr.Error())
|
||||
}
|
||||
}
|
||||
|
|
@ -113,7 +115,7 @@ func SyncDeep(i Importer) (errs SyncReport) {
|
|||
|
||||
errs.DateStart = startTime
|
||||
exceptions, sterrs := SyncThemes(i)
|
||||
for _, sterr := range sterrs {
|
||||
for _, sterr := range multierr.Errors(sterrs) {
|
||||
errs.ThemesSync = append(errs.ThemesSync, sterr.Error())
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +125,7 @@ func SyncDeep(i Importer) (errs SyncReport) {
|
|||
|
||||
for tid, theme := range themes {
|
||||
stderrs := SyncThemeDeep(i, theme, tid, themeStep, exceptions[theme.Path])
|
||||
for _, stderr := range stderrs {
|
||||
for _, stderr := range multierr.Errors(stderrs) {
|
||||
errs.Themes[theme.Name] = append(errs.Themes[theme.Name], stderr.Error())
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +201,7 @@ func EditDeepReport(errs *SyncReport, erase bool) {
|
|||
}
|
||||
|
||||
// SyncThemeDeep performs a recursive synchronisation: from challenges to challenge items.
|
||||
func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8, exceptions *CheckExceptions) (errs []error) {
|
||||
func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8, exceptions *CheckExceptions) (errs error) {
|
||||
var ex_exceptions map[int]*CheckExceptions
|
||||
|
||||
oneThemeDeepSync.Lock()
|
||||
|
|
@ -214,15 +216,15 @@ func SyncThemeDeep(i Importer, theme *fic.Theme, tid int, themeStep uint8, excep
|
|||
log.Printf("Deep synchronization in progress: %d/255 - doing Theme %q, Exercice %q: %q\n", DeepSyncProgress, theme.Name, exercice.Title, exercice.Path)
|
||||
|
||||
DeepSyncProgress = 3 + uint8(tid)*themeStep + uint8(eid)*exerciceStep
|
||||
errs = append(errs, SyncExerciceFiles(i, exercice, ex_exceptions[eid])...)
|
||||
errs = multierr.Append(errs, SyncExerciceFiles(i, exercice, ex_exceptions[eid]))
|
||||
|
||||
DeepSyncProgress += exerciceStep / 3
|
||||
flagsBindings, ferrs := SyncExerciceFlags(i, exercice, ex_exceptions[eid])
|
||||
errs = append(errs, ferrs...)
|
||||
errs = multierr.Append(errs, ferrs)
|
||||
|
||||
DeepSyncProgress += exerciceStep / 3
|
||||
_, herrs := SyncExerciceHints(i, exercice, flagsBindings, ex_exceptions[eid])
|
||||
errs = append(errs, herrs...)
|
||||
errs = multierr.Append(errs, herrs)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue