{"record":{"id":"25c69b2b91e35197","repo":"slimtoolkit/slim","slug":"couldn-t-set-key-s-no-corresponding-struct-field","errorCode":null,"errorMessage":"Couldn't set key %s, no corresponding struct field found","messagePattern":"Couldn't set key (.+?), no corresponding struct field found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/system/os_release.go","lineNumber":72,"sourceCode":"func stripQuotes(val string) string {\n\tif len(val) > 0 && val[0] == '\"' {\n\t\treturn val[1 : len(val)-1]\n\t}\n\treturn val\n}\n\nfunc (osr *OsRelease) setIfPossible(key, val string) error {\n\tv := reflect.ValueOf(osr).Elem()\n\tfor i := 0; i < v.NumField(); i++ {\n\t\tfieldValue := v.Field(i)\n\t\tfieldType := v.Type().Field(i)\n\t\toriginalName := fieldType.Tag.Get(\"osr\")\n\t\tif key == originalName && fieldValue.Kind() == reflect.String {\n\t\t\tfieldValue.SetString(val)\n\t\t\treturn nil\n\t\t}\n\t}\n\treturn fmt.Errorf(\"Couldn't set key %s, no corresponding struct field found\", key)\n}\n\nfunc parseLine(osrLine string) (string, string, error) {\n\tif osrLine == \"\" {\n\t\treturn \"\", \"\", nil\n\t}\n\n\tvals := strings.Split(osrLine, \"=\")\n\tif len(vals) != 2 {\n\t\treturn \"\", \"\", fmt.Errorf(\"Expected %s to split by '=' char into two strings, instead got %d strings\", osrLine, len(vals))\n\t}\n\tkey := vals[0]\n\tval := stripQuotes(vals[1])\n\treturn key, val, nil\n}\n\nfunc (osr *OsRelease) ParseOsRelease(osReleaseContents []byte) error {\n\tr := bytes.NewReader(osReleaseContents)","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/slimtoolkit/slim/blob/81940d17fa112cc678e32209214bcb2355cb3004/pkg/system/os_release.go#L54-L90","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Upgrade the library to a version whose OsRelease struct covers the new keys","Add a struct field with the matching `osr:\"KEY\"` tag to the OsRelease struct","Pre-filter the file, or ignore unknown keys if your version tolerates them","Confirm which key failed — the error message names it"],"exampleFix":"// before\ntype OsRelease struct { Name string `osr:\"NAME\"` }\n// after\ntype OsRelease struct {\n    Name    string `osr:\"NAME\"`\n    ImageID string `osr:\"IMAGE_ID\"` // newly added key\n}","handlingStrategy":"fallback","validationCode":"// inspect which keys the file has before parsing\nkeys := map[string]bool{}\nfor _, line := range lines {\n    if i := strings.Index(line, \"=\"); i > 0 { keys[line[:i]] = true }\n}\n// compare against supported osr tags / upgrade if unknown keys exist","typeGuard":null,"tryCatchPattern":"osr, err := system.ParseOsRelease(path)\nif err != nil && strings.Contains(err.Error(), \"no corresponding struct field found\") {\n    log.Warnf(\"unknown os-release key, continuing with partial data: %v\", err)\n    osr = partialResult // fall back to whatever was parsed\n}","preventionTips":["Keep the library updated for new os-release spec keys","Add osr tags for vendor-specific keys you encounter","Log unknown keys instead of failing hard where possible","Pin distro images to known os-release schemas"],"tags":["parsing","reflection","os-release"],"backgroundTag":"unknown-os-release-key","analyzedSha":"81940d17fa112cc678e32209214bcb2355cb3004","analyzedAt":"2026-08-31T23:06:12.682Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}