TheAlgorithms/Go · error
Invalid isogram order provided
Error message
Invalid isogram order provided
What it means
IsIsogram checks whether a word is an isogram (no repeating letters) of a requested order (First..Third). The order parameter selects which isogram variant to test; passing any value outside that enum range means the requested check is undefined, so the function refuses with this error.
Source
Thrown at strings/isisogram.go:36
const (
First IsogramOrder = iota + 1
Second
Third
)
func hasDigit(text string) bool {
re := regexp.MustCompile(`\d`)
return re.MatchString(text)
}
func hasSymbol(text string) bool {
re := regexp.MustCompile(`[-!@#$%^&*()+]`)
return re.MatchString(text)
}
func IsIsogram(text string, order IsogramOrder) (bool, error) {
if order < First || order > Third {
return false, errors.New("Invalid isogram order provided")
}
text = strings.ToLower(text)
text = strings.Join(strings.Fields(text), "")
if hasDigit(text) || hasSymbol(text) {
return false, errors.New("Cannot contain numbers or symbols")
}
letters := make(map[string]int)
for _, c := range text {
l := string(c)
if _, ok := letters[l]; ok {
letters[l] += 1
if letters[l] > 3 {
return false, nil
}View on GitHub (pinned to 5ba447ec5f)
Solutions
- Pass one of the defined constants: First, Second, or Third
- Validate/normalize the incoming order value (or map config strings to the enum) before calling
- Add an explicit switch/mapping that defaults unknown values to a valid order
Example fix
// before
IsIsogram("dermatoglyphics", userOrder) // userOrder = 0
// after
if userOrder < isogram.First || userOrder > isogram.Third { userOrder = isogram.First }
IsIsogram("dermatoglyphics", userOrder) Defensive patterns
Strategy: validation
Validate before calling
if order < isogram.First || order > isogram.Third {
return false, fmt.Errorf("unsupported isogram order: %v", order)
}
ok, err := isogram.IsIsogram(text, order) Type guard
func validOrder(o IsogramOrder) bool {
return o >= First && o <= Third
} Try / catch
ok, err := isogram.IsIsogram(text, order)
if err != nil {
if strings.Contains(err.Error(), "Invalid isogram order") {
// fall back to First or reject input
}
return err
} Prevention
- Only pass the exported enum constants, never raw ints
- Map external config/JSON strings to the enum with a validated lookup
- Add a table-driven test enumerating all valid orders plus boundary values
When it happens
Trigger: Calling IsIsogram(text, order) with an order value less than First or greater than Third — e.g. a zero value IsogramOrder, an unvalidated int cast, or an off-by-one enum constant.
Common situations: Constructing the order from user input or configuration without mapping it to the enum; adding a new enum constant and forgetting bounds; JSON/config deserialization yielding 0 or an unknown numeric order.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Cannot contain numbers or symbols
- character not available in charmap at position: %v
- strings must have a same length
AI-assisted analysis of TheAlgorithms/Go@5ba447ec5f (2026-09-02).
Data as JSON: /api/errors/61eece1bc9e63796.
Report an issue: GitHub.