{"record":{"id":"2248158c86f18153","repo":"hyperledger/fabric","slug":"marshalling-failed","errorCode":null,"errorMessage":"marshalling failed","messagePattern":"marshalling failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/policy/principal.go","lineNumber":58,"sourceCode":"\t\tlocalMSP: localMSP,\n\t}\n}\n\ntype localMSPPrincipalGetter struct {\n\tlocalMSP msp.MSP\n}\n\nfunc (m *localMSPPrincipalGetter) Get(role string) (*protomsp.MSPPrincipal, error) {\n\tmspid, err := m.localMSP.GetIdentifier()\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"could not extract local msp identifier\")\n\t}\n\n\tswitch role {\n\tcase Admins:\n\t\tprincipalBytes, err := proto.Marshal(&protomsp.MSPRole{Role: protomsp.MSPRole_ADMIN, MspIdentifier: mspid})\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"marshalling failed\")\n\t\t}\n\n\t\treturn &protomsp.MSPPrincipal{\n\t\t\tPrincipalClassification: protomsp.MSPPrincipal_ROLE,\n\t\t\tPrincipal:               principalBytes,\n\t\t}, nil\n\tcase Members:\n\t\tprincipalBytes, err := proto.Marshal(&protomsp.MSPRole{Role: protomsp.MSPRole_MEMBER, MspIdentifier: mspid})\n\t\tif err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"marshalling failed\")\n\t\t}\n\n\t\treturn &protomsp.MSPPrincipal{\n\t\t\tPrincipalClassification: protomsp.MSPPrincipal_ROLE,\n\t\t\tPrincipal:               principalBytes,\n\t\t}, nil\n\tdefault:\n\t\treturn nil, errors.Errorf(\"MSP Principal role [%s] not recognized\", role)","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/policy/principal.go#L40-L76","documentation":"In localMSPPrincipalGetter.Get, when role == Admins the code builds an MSPRole proto (ADMIN + local MSP id) and marshals it with proto.Marshal. 'marshalling failed' wraps any protobuf serialization error. In practice this is nearly unreachable with a valid local MSP since MSPRole contains only a string and an enum.","triggerScenarios":"proto.Marshal fails while serializing the MSPRole{Role: ADMIN, MspIdentifier: mspid} message inside Get(\"Admins\") — realistically only from a corrupted protobuf runtime/registry state or an invalid MspIdentifier string causing serialization issues.","commonSituations":"Mismatched or broken fabric-protos-go-apiv2 / google.golang.org/protobuf dependency versions during custom builds or vendor corruption; regression tests injecting a mock local MSP whose GetIdentifier returns pathological data.","solutions":["Run go mod tidy / go mod vendor to fix fabric-protos-go-apiv2 and protobuf runtime version mismatch","Rebuild the binary to clear corrupted vendor state","Inspect the wrapped error (errors.Cause) for the underlying marshal reason"],"exampleFix":"// before\nprincipalBytes, err := proto.Marshal(&protomsp.MSPRole{Role: protomsp.MSPRole_ADMIN, MspIdentifier: mspid})\nif err != nil { return nil, errors.Wrap(err, \"marshalling failed\") }\n// after\nprincipalBytes, err := proto.Marshal(&protomsp.MSPRole{Role: protomsp.MSPRole_ADMIN, MspIdentifier: mspid})\nif err != nil { return nil, errors.Wrapf(err, \"marshalling MSPRole ADMIN for msp %s failed\", mspid) }","handlingStrategy":"try-catch","validationCode":"if mspid == \"\" {\n    return errors.New(\"local MSP identifier is empty; MSP not initialized\")\n}","typeGuard":null,"tryCatchPattern":"principal, err := getter.Get(\"Admins\")\nif err != nil {\n    if strings.Contains(err.Error(), \"marshalling failed\") {\n        return fmt.Errorf(\"protobuf serialization failure for ADMIN principal: %w\", err)\n    }\n    return err\n}","preventionTips":["Pin compatible versions of fabric-protos-go-apiv2 and google.golang.org/protobuf","Run go mod verify / go mod tidy in CI to catch corrupted vendor trees","Treat any occurrence as an environment/build defect, not a runtime data problem"],"tags":["hyperledger-fabric","protobuf","marshalling","msp"],"backgroundTag":"protobuf-marshalling-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"}