{"record":{"id":"18e41bbe9519b10a","repo":"slimtoolkit/slim","slug":"malformed-find-utf8-s","errorCode":null,"errorMessage":"malformed find utf8: %s","messagePattern":"malformed find utf8: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/app/master/command/xray/cli.go","lineNumber":573,"sourceCode":"\t\tmatchers = append(matchers, &m)\n\t}\n\n\treturn matchers, nil\n}\n\nfunc parseDetectUTF8(raw string) (*dockerimage.UTF8Detector, error) {\n\tif raw == \"\" {\n\t\treturn nil, nil\n\t}\n\n\tvar detector dockerimage.UTF8Detector\n\tif raw == \"dump\" {\n\t\tdetector.Dump = true\n\t\tdetector.DumpConsole = true\n\t} else if strings.HasPrefix(raw, \"dump:\") {\n\t\tparts := strings.SplitN(raw, \":\", 2)\n\t\tif len(parts) != 2 {\n\t\t\treturn nil, fmt.Errorf(\"malformed find utf8: %s\", raw)\n\t\t}\n\n\t\tdetector.Dump = true\n\n\t\toutTarget := strings.TrimSpace(parts[1])\n\t\tif len(outTarget) == 0 || outTarget == dockerimage.CDMDumpToConsole {\n\t\t\tdetector.DumpConsole = true\n\t\t} else {\n\t\t\tif strings.Count(outTarget, \":\") == 2 {\n\t\t\t\tparts = strings.SplitN(outTarget, \":\", 3)\n\t\t\t\tif len(parts) != 3 {\n\t\t\t\t\treturn nil, fmt.Errorf(\"malformed find utf8: %s\", raw)\n\t\t\t\t}\n\t\t\t\toutTarget = parts[0]\n\t\t\t\t_ = parts[1] // TODO implemement path pattern matcher\n\t\t\t\tmaxSizeBytes := parts[2]\n\t\t\t\tvar err error\n\t\t\t\tdetector.MaxSizeBytes, err = strconv.Atoi(maxSizeBytes)","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/app/master/command/xray/cli.go#L555-L591","documentation":"parseDetectUTF8 parses the xray --find-utf8 flag value (pkg/app/master/command/xray/cli.go:573). For values starting with 'dump:', the remainder must split into exactly 2 parts ('dump:<target>'), which effectively means any non-empty suffix; the check fails only when SplitN yields fewer than 2 parts. Because strings.SplitN(s, \":\", 2) on any 'dump:'-prefixed string already yields at least 2 parts, this error is nearly unreachable in practice, but it guards the 'dump:target' contract where the target is a console marker, a directory, or a directory:path-regex:maxBytes spec.","triggerScenarios":"Theoretically, a 'dump:'-prefixed --find-utf8 value that doesn't produce 2 SplitN fields — practically unreachable since any non-empty suffix after 'dump:' yields 2 fields; it acts as a defensive assertion in the parse path.","commonSituations":"Users constructing exotic 'dump:' values and hitting parse issues downstream (e.g. invalid MaxSizeBytes instead produce strconv errors); this specific error mainly surfaces if parsing logic or flag strings change between versions.","solutions":["Use one of the supported forms: 'dump' (console), 'dump:<dir>', or 'dump:<dir>:<path-regex>:<max-size-bytes>'.","If you only want UTF-8 detection without dumping, pass a plain path pattern without the 'dump:' prefix.","If this error appears, upgrade/check your slim version — the flag grammar may have changed between releases.","Ensure the value after 'dump:' is non-empty (use 'dump:console' or an explicit directory)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// validate a --find-utf8 value before invoking the CLI\nfunc validFindUTF8(raw string) bool {\n    switch {\n    case raw == \"\" || raw == \"dump\":\n        return true\n    case strings.HasPrefix(raw, \"dump:\"):\n        target := strings.TrimPrefix(raw, \"dump:\")\n        if target == \"\" || !strings.Contains(target, \":\") {\n            return true // console or plain dir\n        }\n        n := strings.Count(target, \":\")\n        return n == 2 || n == 3\n    default:\n        return true // plain pattern\n    }\n}","typeGuard":null,"tryCatchPattern":"detector, err := parseDetectUTF8(raw)\nif err != nil {\n    if strings.HasPrefix(err.Error(), \"malformed find utf8\") {\n        fmt.Fprintf(os.Stderr, \"use dump | dump:dir | dump:dir:path:maxBytes: %v\\n\", err)\n        os.Exit(2)\n    }\n    return err\n}","preventionTips":["Prefer the simple forms: 'dump' or 'dump:<dir>'.","If specifying max bytes, use the full 3-field target: dir:path:maxBytes.","Avoid colons in the path-pattern portion of the target.","Pin the slim version — the find-utf8 grammar has TODO gaps that may change."],"tags":["cli","xray","utf8-detection","slimtoolkit"],"backgroundTag":"malformed-matcher-syntax","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}