{"record":{"id":"61eece1bc9e63796","repo":"TheAlgorithms/Go","slug":"invalid-isogram-order-provided","errorCode":null,"errorMessage":"Invalid isogram order provided","messagePattern":"Invalid isogram order provided","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"strings/isisogram.go","lineNumber":36,"sourceCode":"const (\n\tFirst IsogramOrder = iota + 1\n\tSecond\n\tThird\n)\n\nfunc hasDigit(text string) bool {\n\tre := regexp.MustCompile(`\\d`)\n\treturn re.MatchString(text)\n}\n\nfunc hasSymbol(text string) bool {\n\tre := regexp.MustCompile(`[-!@#$%^&*()+]`)\n\treturn re.MatchString(text)\n}\n\nfunc IsIsogram(text string, order IsogramOrder) (bool, error) {\n\tif order < First || order > Third {\n\t\treturn false, errors.New(\"Invalid isogram order provided\")\n\t}\n\n\ttext = strings.ToLower(text)\n\ttext = strings.Join(strings.Fields(text), \"\")\n\n\tif hasDigit(text) || hasSymbol(text) {\n\t\treturn false, errors.New(\"Cannot contain numbers or symbols\")\n\t}\n\n\tletters := make(map[string]int)\n\tfor _, c := range text {\n\t\tl := string(c)\n\t\tif _, ok := letters[l]; ok {\n\t\t\tletters[l] += 1\n\n\t\t\tif letters[l] > 3 {\n\t\t\t\treturn false, nil\n\t\t\t}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/strings/isisogram.go#L18-L54","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nIsIsogram(\"dermatoglyphics\", userOrder) // userOrder = 0\n// after\nif userOrder < isogram.First || userOrder > isogram.Third { userOrder = isogram.First }\nIsIsogram(\"dermatoglyphics\", userOrder)","handlingStrategy":"validation","validationCode":"if order < isogram.First || order > isogram.Third {\n    return false, fmt.Errorf(\"unsupported isogram order: %v\", order)\n}\nok, err := isogram.IsIsogram(text, order)","typeGuard":"func validOrder(o IsogramOrder) bool {\n    return o >= First && o <= Third\n}","tryCatchPattern":"ok, err := isogram.IsIsogram(text, order)\nif err != nil {\n    if strings.Contains(err.Error(), \"Invalid isogram order\") {\n        // fall back to First or reject input\n    }\n    return err\n}","preventionTips":["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"],"tags":["isogram","enum-validation","strings"],"backgroundTag":"invalid-enum-value","analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}