{"record":{"id":"4d17b83bb454c67b","repo":"vitessio/vitess","slug":"invalid-truncation-location-d","errorCode":null,"errorMessage":"invalid truncation location: %d","messagePattern":"invalid truncation location: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/textutil/strings.go","lineNumber":164,"sourceCode":"// length using the provided truncation indicator in place of the truncated text\n// in the specified location of the original string.\nfunc TruncateText(text string, limit int, location TruncationLocation, indicator string) (string, error) {\n\tol := len(text)\n\tif ol <= limit {\n\t\treturn text, nil\n\t}\n\tif len(indicator)+2 >= limit {\n\t\treturn \"\", errors.New(\"the truncation indicator is too long for the provided text\")\n\t}\n\tswitch location {\n\tcase TruncationLocationMiddle:\n\t\tprefix := (limit / 2) - len(indicator)\n\t\tsuffix := (ol - (prefix + len(indicator))) + 1\n\t\treturn fmt.Sprintf(\"%s%s%s\", text[:prefix], indicator, text[suffix:]), nil\n\tcase TruncationLocationEnd:\n\t\treturn text[:limit-(len(indicator)+1)] + indicator, nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"invalid truncation location: %d\", location)\n\t}\n}\n","sourceCodeStart":146,"sourceCodeEnd":167,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/textutil/strings.go#L146-L167","documentation":"TruncateText in go/textutil/strings.go takes an explicit truncation location; any value other than TruncationLocationStart, TruncationLocationMiddle, or TruncationLocationEnd hits the default branch and returns this error. It enforces the enum contract instead of guessing a behavior.","triggerScenarios":"Calling textutil.TruncateText(text, limit, indicator, location) with a location int that is not one of the defined TruncationLocation constants (e.g. 3, -1, or a value cast from elsewhere).","commonSituations":"Switching API versions where a new/renamed location constant is missed; computing the location dynamically and going out of range; copying call sites with magic numbers.","solutions":["Pass one of the exported constants: TruncationLocationStart, TruncationLocationMiddle, or TruncationLocationEnd","Replace magic-number locations in call sites with the constants","Clamp or map dynamic location values to a valid constant before calling"],"exampleFix":"// before\ntextutil.TruncateText(s, 80, \"...\", 3)\n// after\ntextutil.TruncateText(s, 80, \"...\", textutil.TruncationLocationMiddle)","handlingStrategy":"validation","validationCode":"func validLocation(l textutil.TruncationLocation) bool {\n\tswitch l {\n\tcase textutil.TruncationLocationStart, textutil.TruncationLocationMiddle, textutil.TruncationLocationEnd:\n\t\treturn true\n\t}\n\treturn false\n}","typeGuard":null,"tryCatchPattern":"out, err := textutil.TruncateText(s, 80, \"...\", loc)\nif err != nil {\n\tout, _ = textutil.TruncateText(s, 80, \"...\", textutil.TruncationLocationEnd)\n}","preventionTips":["Always use the exported TruncationLocation* constants, never raw ints","Add a switch exhaustiveness check (golangci default-case linter) over the enum","Clamp externally sourced location values into the valid range before calling"],"tags":["go","textutil","invalid-argument"],"backgroundTag":"invalid-enum-value","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}