{"record":{"id":"a4af6a74752bae16","repo":"GoogleContainerTools/skaffold","slug":"yaml-tag-filepath-needs-struct-field-q-to-be-st","errorCode":null,"errorMessage":"yaml tag `filepath` needs struct field %q to be string or string slice","messagePattern":"yaml tag `filepath` needs struct field %q to be string or string slice","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/tags/paths.go","lineNumber":89,"sourceCode":"\t\t\t\t\t\telem := v.Index(j)\n\t\t\t\t\t\tpath := elem.String()\n\t\t\t\t\t\tif path == \"\" || filepath.IsAbs(path) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\telem.SetString(filepath.Join(base, path))\n\t\t\t\t\t\tlog.Entry(context.TODO()).Tracef(\"setting absolute paths for config field %q index %d\", f.Name, j)\n\t\t\t\t\t}\n\t\t\t\tcase map[string]string:\n\t\t\t\t\tfor _, key := range v.MapKeys() {\n\t\t\t\t\t\tpath := v.MapIndex(key).String()\n\t\t\t\t\t\tif path == \"\" || filepath.IsAbs(path) {\n\t\t\t\t\t\t\tcontinue\n\t\t\t\t\t\t}\n\t\t\t\t\t\tv.SetMapIndex(key, reflect.ValueOf(filepath.Join(base, path)))\n\t\t\t\t\t\tlog.Entry(context.TODO()).Tracef(\"setting absolute paths for config field %q key %q\", f.Name, key.String())\n\t\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn []error{fmt.Errorf(\"yaml tag `filepath` needs struct field %q to be string or string slice\", f.Name)}\n\t\t\t\t}\n\t\t\t\tcontinue\n\t\t\t}\n\n\t\t\tif v.Kind() != reflect.Pointer {\n\t\t\t\tv = v.Addr()\n\t\t\t}\n\t\t\tif elemErrs := makeFilePathsAbsolute(v.Interface(), base); elemErrs != nil {\n\t\t\t\terrs = append(errs, elemErrs...)\n\t\t\t}\n\t\t}\n\t\treturn errs\n\tcase reflect.Slice:\n\t\tvar errs []error\n\t\tfor i := 0; i < parentStruct.Len(); i++ {\n\t\t\telem := parentStruct.Index(i)\n\t\t\tif elem.Kind() != reflect.Pointer {\n\t\t\t\telem = elem.Addr()","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/tags/paths.go#L71-L107","documentation":"Skaffold walks its config structs via reflection, and struct fields tagged `filepath:\"true\"` must hold a string or string slice so relative paths can be made absolute. If such a field holds any other kind (map, struct, int, etc.), the walker cannot process it and returns this error naming the field.","triggerScenarios":"Running MakeFilePathsAbsolute over a config struct where a field with the yaml `filepath` tag is of a kind other than string or []string — typically a developer error when adding/changing a config field in the latest config package.","commonSituations":"Adding a new config field with the filepath tag but a composite type; changing an existing string filepath field to a map without removing the tag; third-party/embedded structs reusing the tag incorrectly.","solutions":["Change the field's type to string or []string","Remove the `filepath` yaml tag if the field no longer holds paths","For map-typed path fields, add an explicit map-handling branch in paths.go instead of the tag"],"exampleFix":"// before\ntype Config struct {\n    Manifests map[string]string `yaml:\"manifests\" filepath:\"true\"`\n}\n\n// after\ntype Config struct {\n    Manifests []string `yaml:\"manifests\" filepath:\"true\"`\n}","handlingStrategy":"type-guard","validationCode":"if v.Kind() != reflect.String && v.Kind() != reflect.Slice {\n    return fmt.Errorf(\"field %q with filepath tag must be string or []string\", f.Name)\n}","typeGuard":"func isPathKind(v reflect.Value) bool {\n    if v.Kind() == reflect.String { return true }\n    return v.Kind() == reflect.Slice && v.Type().Elem().Kind() == reflect.String\n}","tryCatchPattern":"if errs := tags.MakeFilePathsAbsolute(cfg, dir); len(errs) > 0 {\n    for _, e := range errs {\n        if strings.Contains(e.Error(), \"needs struct field\") {\n            return fmt.Errorf(\"config struct bug, fix field type or remove filepath tag: %w\", e)\n        }\n    }\n}","preventionTips":["Only apply the `filepath` yaml tag to string or []string fields","Add a unit test walking all config structs with MakeFilePathsAbsolute","When changing a field's type, audit its struct tags"],"tags":["skaffold","reflection","config","developer-error"],"backgroundTag":"filepath-field-type-invalid","analyzedSha":"a1189de023efc32d4b8e11f395acc678aa555011","analyzedAt":"2026-09-05T12:09:27.064Z","contentChangedAt":"2026-09-05T12:09:27.064Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}