Skip to content
Snippets Groups Projects
Commit f0a913bf authored by Balthazar Wilson's avatar Balthazar Wilson
Browse files

fix: handle both swf/scf error and tb error

parent 3d9b7d77
No related branches found
No related tags found
1 merge request!6add: error handling
......@@ -28,9 +28,9 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern
return func(p Profile) ([]Alternative, error) {
//récupération du décompte
count, err := swf(p)
if err != nil {
return nil, err
count, errSWF := swf(p)
if errSWF != nil {
return nil, errSWF
}
//préparation de la sortie
var sortedAlts []Alternative
......@@ -45,7 +45,10 @@ func SWFFactory(swf func(Profile) (Count, error), tb func([]Alternative) (Altern
}
//Départage
for len(bestAlts) > 0 {
bestAlt, _ := tb(bestAlts)
bestAlt, errTB := tb(bestAlts)
if errTB != nil {
return nil, errTB
}
//ajout de la meilleure alternative post-tie break
sortedAlts = append(sortedAlts, bestAlt)
//suppression de l'alternative dans bestAlts
......@@ -82,16 +85,13 @@ func Test_sWFFactory() {
func SCFFactory(scf func(p Profile) ([]Alternative, error), tb func([]Alternative) (Alternative, error)) func(Profile) (Alternative, error) {
return func(p Profile) (Alternative, error) {
//récupération des meilleures alternatives
bestAlts, err1 := scf(p)
if err1 != nil {
return Alternative(0), err1
bestAlts, errSCF := scf(p)
if errSCF != nil {
return Alternative(0), errSCF
}
//récupération de la meilleure alternative
bestAlt, err2 := tb(bestAlts)
if err2 != nil {
return Alternative(0), err2
}
return bestAlt, nil
bestAlt, errTB := tb(bestAlts)
return bestAlt, errTB
}
}
func Test_sCFFactory() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment