{"record":{"id":"2450c180da097ef7","repo":"TheAlgorithms/Go","slug":"provided-size-d-is-too-small-to-use-to-slice-stri","errorCode":null,"errorMessage":"provided size %d is too small to use to slice string %q of len %d","messagePattern":"provided size (.+?) is too small to use to slice string %q of len (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cipher/polybius/polybius.go","lineNumber":31,"sourceCode":")\n\n// Polybius is struct having size, characters, and key\ntype Polybius struct {\n\tsize       int\n\tcharacters string\n\tkey        string\n}\n\n// NewPolybius returns a pointer to object of Polybius.\n// If the size of \"chars\" is longer than \"size\",\n// \"chars\" are truncated to \"size\".\nfunc NewPolybius(key string, size int, chars string) (*Polybius, error) {\n\tif size < 0 {\n\t\treturn nil, fmt.Errorf(\"provided size %d cannot be negative\", size)\n\t}\n\tkey = strings.ToUpper(key)\n\tif size > len(chars) {\n\t\treturn nil, fmt.Errorf(\"provided size %d is too small to use to slice string %q of len %d\", size, chars, len(chars))\n\t}\n\tfor _, r := range chars {\n\t\tif (r < 'a' || r > 'z') && (r < 'A' || r > 'Z') {\n\t\t\treturn nil, fmt.Errorf(\"provided string %q should only contain latin characters\", chars)\n\t\t}\n\t}\n\tchars = strings.ToUpper(chars)[:size]\n\tfor i, r := range chars {\n\t\tif strings.ContainsRune(chars[i+1:], r) {\n\t\t\treturn nil, fmt.Errorf(\"%q contains same character %q\", chars[i+1:], r)\n\t\t}\n\t}\n\n\tif len(key) != size*size {\n\t\treturn nil, fmt.Errorf(\"len(key): %d must be as long as size squared: %d\", len(key), size*size)\n\t}\n\treturn &Polybius{size, chars, key}, nil\n}","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/TheAlgorithms/Go/blob/5ba447ec5ff3d1213de65b92e726ee74c5d5cc19/cipher/polybius/polybius.go#L13-L49","documentation":"NewPolybius slices the character alphabet to 'size' characters; if size exceeds len(chars) the slice would go out of range, so the constructor rejects the (size, chars) combination naming both values.","triggerScenarios":"Thrown at cipher/polybius/polybius.go:31 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Supply an alphabet at least as long as size (e.g. 25 letters for a 5x5 square)","Lower size to fit the provided chars string","Include 'J' handling or extra symbols to extend a short alphabet"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5ba447ec5ff3d1213de65b92e726ee74c5d5cc19","analyzedAt":"2026-09-02T21:54:30.227Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}