{"record":{"id":"0082a7e8297ab57c","repo":"hyperledger/fabric","slug":"failed-to-marshal-args-0082a7","errorCode":null,"errorMessage":"failed to marshal args","messagePattern":"failed to marshal args","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/lifecycle/chaincode/queryapproved.go","lineNumber":231,"sourceCode":"\nfunc (a *ApprovedQuerier) createProposal() (*pb.Proposal, error) {\n\tvar function string\n\tvar args proto.Message\n\n\tif a.Input.Name != \"\" {\n\t\tfunction = \"QueryApprovedChaincodeDefinition\"\n\t\targs = &lb.QueryApprovedChaincodeDefinitionArgs{\n\t\t\tName:     a.Input.Name,\n\t\t\tSequence: a.Input.Sequence,\n\t\t}\n\t} else {\n\t\tfunction = \"QueryApprovedChaincodeDefinitions\"\n\t\targs = &lb.QueryApprovedChaincodeDefinitionsArgs{}\n\t}\n\n\targsBytes, err := proto.Marshal(args)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"failed to marshal args\")\n\t}\n\tccInput := &pb.ChaincodeInput{Args: [][]byte{[]byte(function), argsBytes}}\n\n\tcis := &pb.ChaincodeInvocationSpec{\n\t\tChaincodeSpec: &pb.ChaincodeSpec{\n\t\t\tChaincodeId: &pb.ChaincodeID{Name: lifecycleName},\n\t\t\tInput:       ccInput,\n\t\t},\n\t}\n\n\tsignerSerialized, err := a.Signer.Serialize()\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"failed to serialize identity\")\n\t}\n\n\tproposal, _, err := protoutil.CreateProposalFromCIS(cb.HeaderType_ENDORSER_TRANSACTION, a.Input.ChannelID, cis, signerSerialized)\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"failed to create ChaincodeInvocationSpec proposal\")","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/lifecycle/chaincode/queryapproved.go#L213-L249","documentation":"ApprovedQuerier.createProposal fails when proto.Marshal cannot serialize the request args struct (QueryApprovedChaincodeDefinitionArgs or QueryApprovedChaincodeDefinitionsArgs) into protobuf bytes. Since these are plain generated message structs, this almost never fires and would indicate a programming bug such as a nil args pointer or corrupted generated types.","triggerScenarios":"createProposal is called by Query with args == nil (only when neither Input.Name nor other fields select a branch, or a future code path assigns no args), or the generated protobuf type fails marshaling.","commonSituations":"Rare; would appear after a fabric-protos version mismatch where the generated message has invalid state, or custom builds of the peer CLI with modified arg structs.","solutions":["Check that you are using matching versions of fabric-protos-go and the peer CLI build","Verify Input fields are set consistently so createProposal's branching always assigns args","Rebuild the CLI/client against the same protobuf version used by the peer","If it persists, capture the underlying err wrapped by this message and file it to Fabric maintainers"],"exampleFix":"// before\nargsBytes, err := proto.Marshal(args)\nif err != nil {\n\treturn nil, errors.Wrap(err, \"failed to marshal args\")\n}\n// after (caller-side check)\nif args == nil {\n\treturn nil, errors.New(\"no query args constructed: specify channel ID and name\")\n}\nargsBytes, err := proto.Marshal(args)\nif err != nil {\n\treturn nil, errors.Wrap(err, \"failed to marshal args\")\n}","handlingStrategy":"try-catch","validationCode":"if args == nil {\n\treturn errors.New(\"query args not constructed\")\n}","typeGuard":"func argsReady(args proto.Message) bool { return args != nil && !reflect.ValueOf(args).IsNil() }","tryCatchPattern":"argsBytes, err := proto.Marshal(args)\nif err != nil {\n\treturn nil, errors.Wrap(err, \"failed to marshal args\")\n}","preventionTips":["Keep fabric-protos-go versions consistent between client and CLI build","Ensure createProposal's branching always assigns a non-nil args struct","Run unit tests exercising createProposal for all Input flag combinations","Log the underlying wrapped marshal error, not just the wrapper message"],"tags":["hyperledger-fabric","protobuf","marshal"],"backgroundTag":"protobuf-marshal-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}