slimtoolkit/slim · warning

malformed find utf8: %s

Error message

malformed find utf8: %s

What it means

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.

Source

Thrown at pkg/app/master/command/xray/cli.go:573

		matchers = append(matchers, &m)
	}

	return matchers, nil
}

func parseDetectUTF8(raw string) (*dockerimage.UTF8Detector, error) {
	if raw == "" {
		return nil, nil
	}

	var detector dockerimage.UTF8Detector
	if raw == "dump" {
		detector.Dump = true
		detector.DumpConsole = true
	} else if strings.HasPrefix(raw, "dump:") {
		parts := strings.SplitN(raw, ":", 2)
		if len(parts) != 2 {
			return nil, fmt.Errorf("malformed find utf8: %s", raw)
		}

		detector.Dump = true

		outTarget := strings.TrimSpace(parts[1])
		if len(outTarget) == 0 || outTarget == dockerimage.CDMDumpToConsole {
			detector.DumpConsole = true
		} else {
			if strings.Count(outTarget, ":") == 2 {
				parts = strings.SplitN(outTarget, ":", 3)
				if len(parts) != 3 {
					return nil, fmt.Errorf("malformed find utf8: %s", raw)
				}
				outTarget = parts[0]
				_ = parts[1] // TODO implemement path pattern matcher
				maxSizeBytes := parts[2]
				var err error
				detector.MaxSizeBytes, err = strconv.Atoi(maxSizeBytes)

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Use one of the supported forms: 'dump' (console), 'dump:<dir>', or 'dump:<dir>:<path-regex>:<max-size-bytes>'.
  2. If you only want UTF-8 detection without dumping, pass a plain path pattern without the 'dump:' prefix.
  3. If this error appears, upgrade/check your slim version — the flag grammar may have changed between releases.
  4. Ensure the value after 'dump:' is non-empty (use 'dump:console' or an explicit directory).
Defensive patterns

Strategy: validation

Validate before calling

// validate a --find-utf8 value before invoking the CLI
func validFindUTF8(raw string) bool {
    switch {
    case raw == "" || raw == "dump":
        return true
    case strings.HasPrefix(raw, "dump:"):
        target := strings.TrimPrefix(raw, "dump:")
        if target == "" || !strings.Contains(target, ":") {
            return true // console or plain dir
        }
        n := strings.Count(target, ":")
        return n == 2 || n == 3
    default:
        return true // plain pattern
    }
}

Try / catch

detector, err := parseDetectUTF8(raw)
if err != nil {
    if strings.HasPrefix(err.Error(), "malformed find utf8") {
        fmt.Fprintf(os.Stderr, "use dump | dump:dir | dump:dir:path:maxBytes: %v\n", err)
        os.Exit(2)
    }
    return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of slimtoolkit/slim@81940d17fa (2026-08-31). Data as JSON: /api/errors/18e41bbe9519b10a. Report an issue: GitHub.