slimtoolkit/slim · warning

Couldn't set key %s, no corresponding struct field found

Error message

Couldn't set key %s, no corresponding struct field found

What it means

os_release.setIfPossible uses reflection to match each key=value pair from an /etc/os-release file against struct fields tagged with 'osr'. If a key has no matching tagged struct field, this error is returned. It means the file contains an attribute the parser's schema doesn't model.

Source

Thrown at pkg/system/os_release.go:72

func stripQuotes(val string) string {
	if len(val) > 0 && val[0] == '"' {
		return val[1 : len(val)-1]
	}
	return val
}

func (osr *OsRelease) setIfPossible(key, val string) error {
	v := reflect.ValueOf(osr).Elem()
	for i := 0; i < v.NumField(); i++ {
		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)

View on GitHub (pinned to 81940d17fa)

Solutions

  1. Upgrade the library to a version whose OsRelease struct covers the new keys
  2. Add a struct field with the matching `osr:"KEY"` tag to the OsRelease struct
  3. Pre-filter the file, or ignore unknown keys if your version tolerates them
  4. Confirm which key failed — the error message names it

Example fix

// before
type OsRelease struct { Name string `osr:"NAME"` }
// after
type OsRelease struct {
    Name    string `osr:"NAME"`
    ImageID string `osr:"IMAGE_ID"` // newly added key
}
Defensive patterns

Strategy: fallback

Validate before calling

// inspect which keys the file has before parsing
keys := map[string]bool{}
for _, line := range lines {
    if i := strings.Index(line, "="); i > 0 { keys[line[:i]] = true }
}
// compare against supported osr tags / upgrade if unknown keys exist

Try / catch

osr, err := system.ParseOsRelease(path)
if err != nil && strings.Contains(err.Error(), "no corresponding struct field found") {
    log.Warnf("unknown os-release key, continuing with partial data: %v", err)
    osr = partialResult // fall back to whatever was parsed
}

Prevention

When it happens

Trigger: ParseOsRelease encounters an os-release key (e.g. a vendor-added or newer-standard key like IMAGE_ID or VARIANT) for which no struct field carries the matching `osr:"KEY"` tag.

Common situations: Newer /etc/os-release spec keys added after the library was written; distro-specific custom keys (e.g. OPENSTACK_*, cloud images); parsing a file variant like /etc/lsb-release with different key names.

Related errors


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