slimtoolkit/slim · warning

Expected %s to split by '=' char into two strings, instead g

Error message

Expected %s to split by '=' char into two strings, instead got %d strings

What it means

os_release.parseLine splits each os-release line on '=' and requires exactly two parts. Lines with zero or multiple '=' characters (values may legitimately contain '=' unless quoted handling is done before) fail with this error naming the offending line and the number of parts produced.

Source

Thrown at pkg/system/os_release.go:82

		fieldValue := v.Field(i)
		fieldType := v.Type().Field(i)
		originalName := fieldType.Tag.Get("osr")
		if key == originalName && fieldValue.Kind() == reflect.String {
			fieldValue.SetString(val)
			return nil
		}
	}
	return fmt.Errorf("Couldn't set key %s, no corresponding struct field found", key)
}

func parseLine(osrLine string) (string, string, error) {
	if osrLine == "" {
		return "", "", nil
	}

	vals := strings.Split(osrLine, "=")
	if len(vals) != 2 {
		return "", "", fmt.Errorf("Expected %s to split by '=' char into two strings, instead got %d strings", osrLine, len(vals))
	}
	key := vals[0]
	val := stripQuotes(vals[1])
	return key, val, nil
}

func (osr *OsRelease) ParseOsRelease(osReleaseContents []byte) error {
	r := bytes.NewReader(osReleaseContents)
	scanner := bufio.NewScanner(r)
	for scanner.Scan() {
		key, val, err := parseLine(scanner.Text())
		if err != nil {
			log.Printf("Warning: got an invalid line error parsing /etc/os-release: %s", err)
			continue
		}
		if err := osr.setIfPossible(key, val); err != nil {
			//log.Printf("Info: %s\n",err)
			//note: ignore, printing these messages causes more confusion...

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Fix the malformed /etc/os-release line so it is KEY="value" with a single '=' and quoted value
  2. Check for unquoted values containing '=' and add quotes around the value
  3. Regenerate the file from the distro package (e.g. reinstall the 'base-files'/'system-release' package)
  4. As a workaround, pre-process the file to strip invalid lines before parsing

Example fix

// before (unquoted value with '=')
BUILD_ID=http://x/?a=1
// after
BUILD_ID="http://x/?a=1"
Defensive patterns

Strategy: validation

Validate before calling

func validOsReleaseLine(line string) bool {
    line = strings.TrimSpace(line)
    if line == "" || strings.HasPrefix(line, "#") { return true }
    return len(strings.Split(line, "=")) == 2
}

Try / catch

osr, err := system.ParseOsRelease(path)
if err != nil && strings.Contains(err.Error(), "to split by '='") {
    log.Warnf("skipping malformed os-release line: %v", err)
    // sanitize the file or parse remaining valid lines
}

Prevention

When it happens

Trigger: ParseOsRelease reads a line without exactly one '=' separator, e.g. a blank-with-comment line, a shell fragment, or an unquoted value containing '=' (such as a CPE or URL with '=' in it).

Common situations: Custom/os-prober-generated release files with shell syntax; vendor files where the value is unquoted and contains '=' (e.g. BUILD_ID=x=y); accidentally concatenating lsb-release output with os-release.

Related errors


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