ask kitten: Better error message when choice letter is not present in choice text. Fixes #6855

This commit is contained in:
Kovid Goyal
2023-11-26 10:10:50 +05:30
parent c10ea63818
commit 9bb85bd294

View File

@@ -93,6 +93,9 @@ func GetChoices(o *Options) (response string, err error) {
}
letter = strings.ToLower(letter)
idx := strings.Index(strings.ToLower(text), letter)
if idx < 0 {
return "", fmt.Errorf("The choice letter %#v is not present in the choice text: %#v", letter, text)
}
idx = len([]rune(strings.ToLower(text)[:idx]))
allowed.Add(letter)
c := Choice{text: text, idx: idx, color: color, letter: letter}