Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions qaengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,25 @@ func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Debugf("Problem already solved.")
return prob, nil
}
if isQuestionDisabled(prob) {
return defaultEngine.FetchAnswer(prob)
}
var err error
logrus.Debug("looping through the engines to try and fetch the answer")
isDisabled := isQuestionDisabled(prob)
for _, engine := range engines {
logrus.Debugf("engine '%T'", engine)
if prob.Desc == "" && engine.IsInteractiveEngine() {
return defaultEngine.FetchAnswer(prob)
}
if isDisabled && engine.IsInteractiveEngine() {
logrus.Debugf("The question belongs to a disabled category so we won't ask the user for the answer")
prob, err = defaultEngine.FetchAnswer(prob)
if err != nil {
return prob, err
}
if prob.Answer != nil {
prob = changeSelectToInputForOther(prob)
}
break
}
prob, err = engine.FetchAnswer(prob)
if err != nil {
if _, ok := err.(*qatypes.ValidationError); ok {
Expand All @@ -175,6 +184,13 @@ func FetchAnswer(prob qatypes.Problem) (qatypes.Problem, error) {
logrus.Debug("there is no interactive engine")
return prob, fmt.Errorf("failed to fetch the answer for problem: %+v . Error: %w", prob, err)
}
if isDisabled {
logrus.Debugf("the question is from a disabled category so try with default engine")
prob, err = defaultEngine.FetchAnswer(prob)
if err != nil || prob.Answer == nil {
return prob, fmt.Errorf("failed to fetch the answer for problem: %+v . Error: %w", prob, err)
}
}
for err != nil || prob.Answer == nil {
prob, err = lastEngine.FetchAnswer(prob)
if err != nil {
Expand Down