{"record":{"id":"5c81c2d0d49a3451","repo":"pulumi/pulumi","slug":"decoding-apiversioncapabilityconfig-returned-w","errorCode":null,"errorMessage":"decoding APIVersionCapabilityConfig returned %w","messagePattern":"decoding APIVersionCapabilityConfig returned %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/common/apitype/service.go","lineNumber":207,"sourceCode":"\t\t\t\tparsed.CopilotExplainPreviewV1 = true\n\t\t\t}\n\t\tcase DeploymentSchemaVersion:\n\t\t\tif entry.Version == 1 {\n\t\t\t\tvar versionConfig DeploymentSchemaVersionConfig\n\t\t\t\tif err := json.Unmarshal(entry.Configuration, &versionConfig); err != nil {\n\t\t\t\t\treturn Capabilities{}, fmt.Errorf(\"decoding DeploymentSchemaVersionConfig returned %w\", err)\n\t\t\t\t}\n\t\t\t\tparsed.DeploymentSchemaVersion = versionConfig.Version\n\t\t\t}\n\t\tcase StackPolicyPacks:\n\t\t\tif entry.Version == 1 {\n\t\t\t\tparsed.StackPolicyPacks = true\n\t\t\t}\n\t\tcase APIVersion:\n\t\t\tif entry.Version == 1 {\n\t\t\t\tvar cfg APIVersionCapabilityConfig\n\t\t\t\tif err := json.Unmarshal(entry.Configuration, &cfg); err != nil {\n\t\t\t\t\treturn Capabilities{}, fmt.Errorf(\"decoding APIVersionCapabilityConfig returned %w\", err)\n\t\t\t\t}\n\t\t\t\tif err := cfg.validate(); err != nil {\n\t\t\t\t\treturn Capabilities{}, fmt.Errorf(\"invalid APIVersionCapabilityConfig: %w\", err)\n\t\t\t\t}\n\t\t\t\tparsed.APIVersion = &cfg\n\t\t\t}\n\t\tcase NeoCLIMode:\n\t\t\tif entry.Version == 1 {\n\t\t\t\tvar cfg NeoCLIModeConfig\n\t\t\t\tif err := json.Unmarshal(entry.Configuration, &cfg); err != nil {\n\t\t\t\t\treturn Capabilities{}, fmt.Errorf(\"decoding NeoCLIModeConfig returned %w\", err)\n\t\t\t\t}\n\t\t\t\tparsed.NeoCLIMode = &cfg\n\t\t\t}\n\t\tcase BeginUpdate:\n\t\t\tif entry.Version == 1 {\n\t\t\t\tparsed.BeginUpdate = true\n\t\t\t}","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/common/apitype/service.go#L189-L225","documentation":"When Parse() encounters the APIVersion capability (version 1), it json.Unmarshals entry.Configuration into APIVersionCapabilityConfig. If the payload cannot be decoded, the failure is wrapped as \"decoding APIVersionCapabilityConfig returned %w\" and Parse() returns an empty Capabilities. It means the backend's API-version negotiation capability blob is not valid JSON for the expected struct.","triggerScenarios":"Calling CapabilitiesResponse.Parse() when the capabilities list contains Capability==APIVersion, Version==1, and Configuration is invalid JSON or has fields whose types do not match APIVersionCapabilityConfig (e.g. a string where a number range/object is expected).","commonSituations":"A backend advertises REST API version negotiation but sends a config payload from an incompatible schema version; proxy or test stubs hand-write the configuration string with syntax errors; schema drift between CLI and service versions.","solutions":["Inspect the raw Configuration JSON for the APIVersion entry and correct it to match APIVersionCapabilityConfig's fields and types.","Print the Configuration bytes before parsing to identify the exact JSON defect.","Align backend and CLI versions so the capability schema matches what the CLI unmarshals.","In test fixtures, marshal a real APIVersionCapabilityConfig value with json.Marshal instead of hand-writing JSON strings.","If API-version negotiation is not required, remove the malformed capability entry from the response."],"exampleFix":"// before\ncfg := APIVersionCapabilityConfig{}\nif err := json.Unmarshal(entry.Configuration, &cfg); err != nil {\n    return Capabilities{}, fmt.Errorf(\"decoding APIVersionCapabilityConfig returned %w\", err)\n}\n// after (validate payload first)\nif !json.Valid(entry.Configuration) {\n    return Capabilities{}, fmt.Errorf(\"APIVersion capability configuration is not valid JSON: %s\", entry.Configuration)\n}\nvar cfg APIVersionCapabilityConfig\nif err := json.Unmarshal(entry.Configuration, &cfg); err != nil {\n    return Capabilities{}, fmt.Errorf(\"decoding APIVersionCapabilityConfig returned %w\", err)\n}","handlingStrategy":"validation","validationCode":"func validAPIVersionConfig(raw json.RawMessage) bool {\n\tif !json.Valid(raw) {\n\t\treturn false\n\t}\n\tvar cfg apitype.APIVersionCapabilityConfig\n\tif err := json.Unmarshal(raw, &cfg); err != nil {\n\t\treturn false\n\t}\n\treturn cfg.validate() == nil\n}","typeGuard":"func isAPIVersionDecodeError(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"decoding APIVersionCapabilityConfig returned\")\n}","tryCatchPattern":"caps, err := resp.Parse()\nif err != nil {\n\tif isAPIVersionDecodeError(err) {\n\t\t// proceed without API-version negotiation\n\t\tcaps.APIVersion = nil\n\t\terr = nil\n\t}\n}\nif err != nil {\n\treturn err\n}","preventionTips":["Marshal test fixtures from real structs with json.Marshal instead of hand-writing JSON.","Run json.Valid() on capability Configuration payloads before calling Parse().","Keep CLI and backend versions aligned so the APIVersion capability schema matches.","Have backends run APIVersionCapabilityConfig.validate() before advertising the capability."],"tags":["go","json","json-unmarshal","capabilities","api-version"],"backgroundTag":"json-unmarshal-error","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-09-01T08:17:40.651Z"}