{"record":{"id":"5df06208ae561dd8","repo":"microsoft/aspire","slug":"aspire-methodname-parameter-q-must-be-one-of-allowed-got-t","errorCode":null,"errorMessage":"aspire: {methodName}: parameter %q must be one of [{allowed}], got %T","messagePattern":"aspire: (.+?): parameter %q must be one of \\[(.+?)\\], got %T","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs","lineNumber":1865,"sourceCode":"    /// emitted code creates a descriptive error and runs the supplied\n    /// errorAction lines (e.g. propagating to a child wrapper) before\n    /// returning. Caller is responsible for choosing the right indentation\n    /// and the right error action for the surrounding shape (sync vs goroutine).\n    /// </summary>\n    private void EmitUnionTypeChecks(\n        string indent,\n        AtsCapabilityInfo capability,\n        string methodName,\n        IReadOnlyList<string> errorActionLines)\n    {\n        foreach (var p in GetUnionParameters(capability))\n        {\n            var paramName = GetLocalIdentifier(p.Name);\n            var allowed = GetUnionAllowedTypes(p.Type!);\n            WriteLine($\"{indent}switch {paramName}.(type) {{\");\n            WriteLine($\"{indent}case {allowed}:\");\n            WriteLine($\"{indent}default:\");\n            WriteLine($\"{indent}\\terr := fmt.Errorf(\\\"aspire: {methodName}: parameter %q must be one of [{allowed}], got %T\\\", \\\"{p.Name}\\\", {paramName})\");\n            foreach (var line in errorActionLines)\n            {\n                WriteLine($\"{indent}\\t{line}\");\n            }\n            WriteLine($\"{indent}}}\");\n        }\n    }\n\n    private void EmitUnionAllowedTypesDoc(AtsCapabilityInfo capability)\n    {\n        foreach (var p in GetUnionParameters(capability))\n        {\n            var allowed = GetUnionAllowedTypes(p.Type!);\n            WriteLine($\"// Allowed types for parameter {p.Name}: {allowed}.\");\n        }\n    }\n\n    private string GetUnionAllowedTypes(AtsTypeRef typeRef)","sourceCodeStart":1847,"sourceCodeEnd":1883,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.CodeGeneration.Go/AtsGoCodeGenerator.cs#L1847-L1883","documentation":"Generated Go union-typed parameters emit a type switch validating the parameter against its allowed types before sending. If the caller passes a value whose dynamic type is not in the union, this error is raised (and typically stored on the errored builder). It is compile-time-safe validation for Go interfaces used as union types.","triggerScenarios":"Passing a value of a concrete type not listed in the union's allowed types to a generated method parameter, e.g. passing int where the union only accepts string or a specific interface.","commonSituations":"Passing the wrong primitive (int vs string), passing nil into a non-nil-allowed union, or using a raw value instead of the generated wrapper type for the union member.","solutions":["Pass one of the allowed types listed in the error message, using the generated wrapper/interface implementations","Convert the value to the expected union member type before the call (e.g. wrap a string in the generated string-variant type)","Regenerate the client if you believe the union should include your type"],"exampleFix":"// before\nbuilder.WithParam(\"port\", 8080) // int not in union\n// after\nbuilder.WithParam(\"port\", \"8080\") // string is allowed","handlingStrategy":"type-guard","validationCode":"switch v := param.(type) {\ncase string, *SomeUnionMember: // allowed types from error message\n\t// ok\ndefault:\n\treturn fmt.Errorf(\"param must be one of the union types, got %T\", param)\n}","typeGuard":"func isAllowedUnionMember(v any) bool {\n\tswitch v.(type) {\n\tcase string, int64, *GeneratedVariant: // mirror the union's allowed types\n\t\treturn true\n\t}\n\treturn false\n}","tryCatchPattern":"if err := rb.WithParam(\"port\", p); err != nil { return err } // check immediately\nterminal, err := rb.Build()\nif err != nil { /* includes union validation failure */ }","preventionTips":["Use the generated variant/wrapper types instead of raw primitives","Read the allowed-type list in the error message and match it","Regenerate the client if a needed union member is missing"],"tags":["go","code-generation","union-type","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}