{"record":{"id":"d64c708473cda3bf","repo":"hyperledger/fabric","slug":"invalid-signer-cannot-be-nil","errorCode":null,"errorMessage":"invalid signer. cannot be nil","messagePattern":"invalid signer\\. cannot be nil","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"protoutil/commonutils.go","lineNumber":168,"sourceCode":"\tcreator, err := id.Serialize()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tnonce, err := CreateNonce()\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\treturn &cb.SignatureHeader{\n\t\tCreator: creator,\n\t\tNonce:   nonce,\n\t}, nil\n}\n\n// NewSignatureHeaderOrPanic returns a signature header and panics on error.\nfunc NewSignatureHeaderOrPanic(id identity.Serializer) *cb.SignatureHeader {\n\tif id == nil {\n\t\tpanic(errors.New(\"invalid signer. cannot be nil\"))\n\t}\n\n\tsignatureHeader, err := NewSignatureHeader(id)\n\tif err != nil {\n\t\tpanic(fmt.Errorf(\"failed generating a new SignatureHeader: %s\", err))\n\t}\n\n\treturn signatureHeader\n}\n\n// SignOrPanic signs a message and panics on error.\nfunc SignOrPanic(signer identity.Signer, msg []byte) []byte {\n\tif signer == nil {\n\t\tpanic(errors.New(\"invalid signer. cannot be nil\"))\n\t}\n\n\tsigma, err := signer.Sign(msg)\n\tif err != nil {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/commonutils.go#L150-L186","documentation":"NewSignatureHeaderOrPanic panics immediately with 'invalid signer. cannot be nil' when the identity.Serializer argument is nil. It is a fail-fast precondition: creating a SignatureHeader requires serializing a signing identity, so a nil signer is a programming error rather than a runtime condition.","triggerScenarios":"Calling NewSignatureHeaderOrPanic(nil) — e.g. the signing identity was never loaded from MSP/certificate material, a dependency injection returned nil, or an <anonymous> callback passed through an unset signer variable.","commonSituations":"Orderer/peer code paths (addBlockSignature) where the signer dependency wasn't initialized because local MSP config is missing or empty; SDK apps constructing blocks without a loaded identity; late-binding of signer after config load failure.","solutions":["Ensure a valid signing identity is loaded (local MSP / identity.Serializer) before constructing the block publisher or signer that reaches this call.","Check the code path that injects the signer — fix nil wiring (e.g. a constructor receiving a nil signer dependency).","Use the non-panicking NewSignatureHeader and validate id != nil yourself if nil signers are expected at runtime.","If using fabric-sdk, confirm the client was created with credentials (wallet/identity) before signing operations."],"exampleFix":"// before\nsigHdr := protoutil.NewSignatureHeaderOrPanic(signer) // panics if signer==nil\n// after\nif signer == nil {\n    return errors.New(\"signer not configured; check local MSP/identity setup\")\n}\nsigHdr, err := protoutil.NewSignatureHeader(signer)","handlingStrategy":"validation","validationCode":"if signer == nil {\n    return errors.New(\"signing identity not configured; check local MSP setup\")\n}\nsigHdr := protoutil.NewSignatureHeaderOrPanic(signer)","typeGuard":"func hasSerializer(id identity.Serializer) bool {\n    return id != nil\n}","tryCatchPattern":"func safeSigHeader(id identity.Serializer) (hdr *cb.SignatureHeader, err error) {\n    defer func() {\n        if r := recover(); r != nil {\n            err = fmt.Errorf(\"NewSignatureHeaderOrPanic: %v\", r)\n        }\n    }()\n    hdr = protoutil.NewSignatureHeaderOrPanic(id)\n    return\n}","preventionTips":["Assert signing identity is loaded at component startup, before any signing path runs","Wire the identity.Serializer through constructors and fail fast on nil dependencies","Use NewSignatureHeader (error-returning) when nil signers are a runtime possibility","Verify local MSP configuration (signcerts/keystore) during deployment health checks"],"tags":["hyperledger-fabric","panic","nil-check","signing"],"backgroundTag":"nil-argument","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"}