Skip to content

Commit

Permalink
fix: when using --qa-enable and --qa-disable the answers to disabled …
Browse files Browse the repository at this point in the history
…questions were not being added to the generated config file (#1163)

Signed-off-by: Harikrishnan Balagopal <[email protected]>
  • Loading branch information
HarikrishnanBalagopal authored Mar 21, 2024
1 parent d049f65 commit 7383e91
Showing 1 changed file with 19 additions and 3 deletions.
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

0 comments on commit 7383e91

Please sign in to comment.