{"record":{"id":"9c8322ca0d989689","repo":"GoogleContainerTools/skaffold","slug":"impossible-intorstring-type","errorCode":null,"errorMessage":"impossible IntOrString.Type","messagePattern":"impossible IntOrString\\.Type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/skaffold/schema/util/int_string.go","lineNumber":78,"sourceCode":"\tval := node.Value\n\ti, err := strconv.Atoi(val)\n\tif err != nil {\n\t\t*t = FromString(val)\n\t} else {\n\t\t*t = FromInt(i)\n\t}\n\treturn nil\n}\n\n// MarshalYAML implements the yaml.Marshaler interface.\nfunc (t IntOrString) MarshalYAML() (interface{}, error) {\n\tswitch t.Type {\n\tcase Int:\n\t\treturn t.IntVal, nil\n\tcase String:\n\t\treturn t.StrVal, nil\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"impossible IntOrString.Type\")\n\t}\n}\n\n// UnmarshalJSON implements the json.Unmarshaler interface.\nfunc (t *IntOrString) UnmarshalJSON(value []byte) error {\n\tif value[0] == '\"' {\n\t\tt.Type = String\n\t\treturn json.Unmarshal(value, &t.StrVal)\n\t}\n\tt.Type = Int\n\treturn json.Unmarshal(value, &t.IntVal)\n}\n\n// MarshalJSON implements the json.Marshaler interface.\nfunc (t IntOrString) MarshalJSON() ([]byte, error) {\n\tswitch t.Type {\n\tcase Int:\n\t\treturn json.Marshal(t.IntVal)","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/GoogleContainerTools/skaffold/blob/a1189de023efc32d4b8e11f395acc678aa555011/pkg/skaffold/schema/util/int_string.go#L60-L96","documentation":"`IntOrString.MarshalYAML` (pkg/skaffold/schema/util/int_string.go:78) serializes a value that can hold either an int or a string, switching on `Type` (Int=0, String=1). The `default` branch is unreachable for correctly constructed values, so this error indicates an IntOrString whose zero-value-ish Type is neither Int nor String — i.e. it was constructed directly with an invalid Type (e.g. `IntOrString{}` with Type left as an out-of-range value) rather than via FromInt/FromString.","triggerScenarios":"Programmatic construction of `util.IntOrString` with a Type value other than 0 or 1 (e.g. copied from an API type with different enum values, or a struct left uninitialized by a third-party constructor), followed by yaml.Marshal of a config containing it. Not producible from normal skaffold.yaml parsing, since UnmarshalYAML always sets Type to Int or String.","commonSituations":"Custom tooling that builds skaffold config structs in Go; mapping from k8s intstr.IntOrString (whose Type uses different iota ordering: String=1, Int=0 in some versions — but any direct assignment of the wrong enum) into skaffold's util.IntOrString without conversion; zero-value struct usage with an explicit bad Type.","solutions":["Construct values with `util.FromInt(v)` or `util.FromString(s)` instead of struct literals","If converting from k8s `intstr.IntOrString`, map by checking `k8sVal.Type == intstr.Int` rather than copying the numeric Type value","Audit code for direct assignments to the Type field and clamp/normalize them to Int or String before marshaling"],"exampleFix":"// before\nios := util.IntOrString{IntVal: 8080} // Type never set correctly\n_ = yaml.Marshal(ios) // panics error path\n// after\nios := util.FromInt(8080)\nout, err := yaml.Marshal(ios)","handlingStrategy":"type-guard","validationCode":"func ok(v util.IntOrString) bool { return v.Type == util.Int || v.Type == util.String }","typeGuard":"func ok(v util.IntOrString) bool { return v.Type == util.Int || v.Type == util.String }","tryCatchPattern":"if _, err := yaml.Marshal(cfg); err != nil && strings.Contains(err.Error(), \"impossible IntOrString.Type\") { return fmt.Errorf(\"malformed IntOrString: %w\", err) }","preventionTips":["Use util.FromInt/FromString constructors","Map k8s intstr by inspection, not raw Type","Unit-test marshaling of config fields"],"tags":["serialization","yaml","invariant-violation"],"backgroundTag":"invalid-enum-value","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"}