{"record":{"id":"b5b0465dcadd7f26","repo":"hyperledger/fabric","slug":"failed-marshaling-signed-data","errorCode":null,"errorMessage":"failed marshaling signed data","messagePattern":"failed marshaling signed data","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"discovery/authcache.go","lineNumber":191,"sourceCode":"\tcache.Lock()\n\tdefer cache.Unlock()\n\tcache.lastSequence = currSeq\n\t// Invalidate entries\n\tcache.entries = make(map[string]error)\n}\n\nfunc (cache *accessCache) lookup(key string) (cacheHit bool, lookupResult error) {\n\tcache.RLock()\n\tdefer cache.RUnlock()\n\n\tlookupResult, cacheHit = cache.entries[key]\n\treturn\n}\n\nfunc signedDataToKey(data protoutil.SignedData) (string, error) {\n\tb, err := asBytes(data)\n\tif err != nil {\n\t\treturn \"\", errors.Wrap(err, \"failed marshaling signed data\")\n\t}\n\treturn hex.EncodeToString(util.ComputeSHA256(b)), nil\n}\n","sourceCodeStart":173,"sourceCodeEnd":195,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/discovery/authcache.go#L173-L195","documentation":"signedDataToKey in discovery/authcache.go:191 marshals protoutil.SignedData to bytes (asBytes), SHA-256 hashes them, and hex-encodes the result as the eligibility cache key. If asBytes fails to marshal the data, the error is wrapped with 'failed marshaling signed data' and propagated to EligibleForService.","triggerScenarios":"Direct calls from EligibleForService (or the test TestSignedDataToKey) with a SignedData struct whose Identity/Data/Signature fields cannot be proto-marshaled into bytes.","commonSituations":"Identity bytes that are not valid protobuf-encodable content; nil or corrupted identity/signature slices; test fixtures with malformed SignedData.","solutions":["Ensure SignedData fields (Identity, Data, Signature) contain valid, non-nil byte slices produced by the normal signing flow","Validate the client certificate/identity bytes are well-formed before making discovery requests","Check the wrapped inner error (%+v) to identify the exact marshaling failure","If in tests, use valid fixture identities instead of hand-crafted byte slices"],"exampleFix":"// before: nil signature in SignedData\nsd := protoutil.SignedData{Identity: idBytes, Data: msg}\n\n// after: fully populated SignedData\nsig, err := signer.Sign(msg)\nif err != nil { return err }\nsd := protoutil.SignedData{Identity: idBytes, Data: msg, Signature: sig}","handlingStrategy":"validation","validationCode":"if _, err := proto.Marshal(&pb.SerializedIdentity{IdBytes: sd.Identity}); err != nil {\n    return fmt.Errorf(\"invalid identity bytes: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"key, err := signedDataToKey(data)\nif err != nil {\n    return fmt.Errorf(\"cannot cache eligibility: %w\", err) // surfaces 'failed marshaling signed data' cause\n}","preventionTips":["Never hand-craft SignedData byte fields; derive them from the standard signing flow","Validate client certificates parse as X.509 before sending discovery requests","In tests, use realistic identity fixtures"],"tags":["hyperledger-fabric","discovery-service","serialization","cache-key"],"backgroundTag":"signed-data-marshaling-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"}