{"record":{"id":"d9bcd916881cefe4","repo":"docker/cli","slug":"invalid-type-t-for-port","errorCode":null,"errorMessage":"invalid type %T for port","messagePattern":"invalid type %T for port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/compose/loader/loader.go","lineNumber":731,"sourceCode":"\t\tports := []any{}\n\t\tfor _, entry := range entries {\n\t\t\tswitch value := entry.(type) {\n\t\t\tcase int:\n\t\t\t\tv, err := toServicePortConfigs(strconv.Itoa(value))\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn data, err\n\t\t\t\t}\n\t\t\t\tports = append(ports, v...)\n\t\t\tcase string:\n\t\t\t\tv, err := toServicePortConfigs(value)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn data, err\n\t\t\t\t}\n\t\t\t\tports = append(ports, v...)\n\t\t\tcase map[string]any:\n\t\t\t\tports = append(ports, value)\n\t\t\tdefault:\n\t\t\t\treturn data, fmt.Errorf(\"invalid type %T for port\", value)\n\t\t\t}\n\t\t}\n\t\treturn ports, nil\n\tdefault:\n\t\treturn data, fmt.Errorf(\"invalid type %T for port\", entries)\n\t}\n}\n\nvar transformStringSourceMap TransformerFunc = func(data any) (any, error) {\n\tswitch value := data.(type) {\n\tcase string:\n\t\treturn map[string]any{\"source\": value}, nil\n\tcase map[string]any:\n\t\treturn data, nil\n\tdefault:\n\t\treturn data, fmt.Errorf(\"invalid type %T for secret\", value)\n\t}\n}","sourceCodeStart":713,"sourceCodeEnd":749,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/compose/loader/loader.go#L713-L749","documentation":"Thrown by transformServicePort in its per-entry loop. When `ports` is a list, each element must be an int, a string (short syntax), or a map (long syntax). Any other element type (bool, nested list, null) hits this default branch.","triggerScenarios":"A service has `ports:` as a list containing a non-port element, e.g. `ports: [80, [81]]`, `ports: [true]`, or `ports: [~]`.","commonSituations":"Bad indentation turning a map into a nested list; templating that injects nulls; mixing port and label entries.","solutions":["Make each entry an int (`80`), a string (`\"8080:80\"`), or a map (`{ target: 80, published: 8080 }`).","Remove stray/null entries introduced by templating."],"exampleFix":"# before\nweb:\n  ports:\n    - 80\n    - [81]\n# after\nweb:\n  ports:\n    - 80\n    - 81","handlingStrategy":"type-guard","validationCode":"func validatePortEntries(ports any) error {\n    list, ok := ports.([]any)\n    if !ok {\n        return nil // outer error 469 handles non-list\n    }\n    for i, e := range list {\n        switch e.(type) {\n        case int, string, map[string]any:\n        default:\n            return fmt.Errorf(\"ports[%d]: invalid type %T\", i, e)\n        }\n    }\n    return nil\n}","typeGuard":"func isPortEntry(v any) bool {\n    switch v.(type) {\n    case int, string, map[string]any:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Keep each ports entry an int, string, or long-form map.","Avoid nested lists or nulls from templating.","Render with `docker compose config` to spot malformed entries."],"tags":["compose","ports","type-mismatch","service"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}