{"record":{"id":"fd087af1703a8cc1","repo":"hyperledger/fabric","slug":"error-marshalling-msp-role-s","errorCode":null,"errorMessage":"error marshalling msp role: %s","messagePattern":"error marshalling msp role: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/policydsl/policyparser.go","lineNumber":198,"sourceCode":"\t\t\tswitch subm[0][3] {\n\t\t\tcase RoleMember:\n\t\t\t\tr = mb.MSPRole_MEMBER\n\t\t\tcase RoleAdmin:\n\t\t\t\tr = mb.MSPRole_ADMIN\n\t\t\tcase RoleClient:\n\t\t\t\tr = mb.MSPRole_CLIENT\n\t\t\tcase RolePeer:\n\t\t\t\tr = mb.MSPRole_PEER\n\t\t\tcase RoleOrderer:\n\t\t\t\tr = mb.MSPRole_ORDERER\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"error parsing role %s\", t)\n\t\t\t}\n\n\t\t\t/* build the principal we've been told */\n\t\t\tmspRole, err := proto.Marshal(&mb.MSPRole{MspIdentifier: subm[0][1], Role: r})\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"error marshalling msp role: %s\", err)\n\t\t\t}\n\n\t\t\tp := &mb.MSPPrincipal{\n\t\t\t\tPrincipalClassification: mb.MSPPrincipal_ROLE,\n\t\t\t\tPrincipal:               mspRole,\n\t\t\t}\n\t\t\tctx.principals = append(ctx.principals, p)\n\n\t\t\t/* create a SignaturePolicy that requires a signature from\n\t\t\t   the principal we've just built*/\n\t\t\tdapolicy := SignedBy(int32(ctx.IDNum))\n\t\t\tpolicies = append(policies, dapolicy)\n\n\t\t\t/* increment the identity counter. Note that this is\n\t\t\t   suboptimal as we are not reusing identities. We\n\t\t\t   can deduplicate them easily and make this puppy\n\t\t\t   smaller. For now it's fine though */\n\t\t\t// TODO: deduplicate principals","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/policydsl/policyparser.go#L180-L216","documentation":"This error is returned by the internal secondPass function of the policy DSL parser (common/policydsl/policyparser.go:198) when the protobuf marshalling of an MSPRole message fails. The parser has already matched a valid 'ORG.ROLE' principal string and resolved the role to an MSPRole_MSPRoleType, but the call to proto.Marshal(&mb.MSPRole{...}) returned an error. In practice this is extremely rare because MSPRole is a simple proto message whose marshal cannot fail with valid input.","triggerScenarios":"Calling policydsl.FromString with a principal like 'Org1.member' when the underlying proto.Marshal of MSPRole{MspIdentifier, Role} fails - essentially only with corrupt protobuf library state, nil registry issues, or an incompatible/older protos dependency where the MspIdentifier field cannot be serialized.","commonSituations":"Broken or mismatched fabric-protos dependency versions; a vendored or replaced protobuf runtime that cannot marshal MSPRole; none in normal usage - developers essentially never hit this in the field.","solutions":["Verify the project imports a consistent, compatible set of github.com/hyperledger/fabric-protos-go-apiv2 and google.golang.org/protobuf versions (run go mod tidy and go mod verify)","Inspect the wrapped error text after 'error marshalling msp role: ' to identify the actual proto failure (e.g. nil pointer, unknown field)","Upgrade fabric-protos-go-apiv2 and the protobuf runtime to versions matching your fabric release","If reproducible, test proto.Marshal directly on an MSPRole value to isolate the proto runtime issue","Rebuild with a clean module cache (go clean -modcache && go mod download) to rule out corrupted vendor/module state"],"exampleFix":"// before (dependency mismatch causing marshal failure)\nrequire github.com/hyperledger/fabric-protos-go-apiv2 v0.0.0-20220101...\n// after (pin a version compatible with your fabric release)\ngo get github.com/hyperledger/fabric-protos-go-apiv2@latest && go mod tidy","handlingStrategy":"validation","validationCode":"import \"google.golang.org/protobuf/proto\"\nimport mb \"github.com/hyperledger/fabric-protos-go-apiv2/msp\"\n\nfunc canMarshalMSPRole(mspID string) error {\n\t_, err := proto.Marshal(&mb.MSPRole{MspIdentifier: mspID, Role: mb.MSPRole_MEMBER})\n\treturn err\n}\n// run at startup: if err := canMarshalMSPRole(\"Org1MSP\"); err != nil { /* fix proto deps */ }","typeGuard":null,"tryCatchPattern":"_, err := policydsl.FromString(policy)\nif err != nil && strings.Contains(err.Error(), \"error marshalling msp role\") {\n\t// proto runtime/dependency problem: verify fabric-protos + protobuf versions\n\treturn fmt.Errorf(\"policy %q: proto runtime issue: %w\", policy, err)\n}","preventionTips":["Pin fabric-protos-go-apiv2 and google.golang.org/protobuf to versions matching your fabric release","Run go mod verify and go mod tidy in CI to catch dependency drift","Smoke-test policydsl.FromString with a sample policy at service startup","Treat any marshal error as a dependency/environment problem, not a policy syntax problem"],"tags":["protobuf","hyperledger-fabric","policies","marshalling"],"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"}