{"record":{"id":"ddbf0d29dd3a2adb","repo":"hyperledger/fabric","slug":"invalid-transaction-type-d","errorCode":null,"errorMessage":"invalid transaction type %d","messagePattern":"invalid transaction type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tx/processor_factory.go","lineNumber":36,"sourceCode":"// ProcessorFactory maintains a mapping between transaction type and associate `ProcessorCreator`\ntype ProcessorFactory struct {\n\tProcessorCreators map[common.HeaderType]tx.ProcessorCreator\n}\n\n// CreateProcessor unmarshals bytes into an Envelope and invokes a ProcessorCreators corresponding to the transaction type\n// present in the ChannelHeader. If successful, this function returns the Processor and simulatedRWSet created by the ProcessorCreators.\n// However, if this function encounters and error in detecting the transaction type or a\n// ProcessorCreators has not been registered for the transaction type, the error returned would be of type\n// `tx.InvalidErr` which implies that the transaction is found to be invalid at the very beginning stage\nfunc (f *ProcessorFactory) CreateProcessor(txEnvelopeBytes []byte) (processor tx.Processor, simulatedRWSet [][]byte, err error) {\n\ttxEnv, err := validateProtoAndConstructTxEnv(txEnvelopeBytes)\n\tif err != nil {\n\t\treturn nil, nil, err\n\t}\n\tc, ok := f.ProcessorCreators[common.HeaderType(txEnv.ChannelHeader.Type)]\n\tif !ok {\n\t\treturn nil, nil, &tx.InvalidErr{\n\t\t\tActualErr:      errors.Errorf(\"invalid transaction type %d\", txEnv.ChannelHeader.Type),\n\t\t\tValidationCode: peer.TxValidationCode_UNKNOWN_TX_TYPE,\n\t\t}\n\t}\n\treturn c.NewProcessor(txEnv)\n}\n\n// validateProtoAndConstructTxEnv attempts to unmarshal the bytes and prepare an instance of struct tx.Envelope\n// It returns an error of type `tx.InvalidErr` if the proto message is found to be invalid\nfunc validateProtoAndConstructTxEnv(txEnvelopeBytes []byte) (*tx.Envelope, error) {\n\ttxenv, err := protoutil.UnmarshalEnvelope(txEnvelopeBytes)\n\tif err != nil {\n\t\treturn nil, &tx.InvalidErr{\n\t\t\tActualErr:      err,\n\t\t\tValidationCode: peer.TxValidationCode_INVALID_OTHER_REASON,\n\t\t}\n\t}\n\n\tif len(txenv.Payload) == 0 {","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/tx/processor_factory.go#L18-L54","documentation":"CreateProcessor looks up a registered processor for the transaction's header type (common.HeaderType) in the factory's ProcessorCreators map. If no creator is registered for that type, it returns an InvalidErr with message 'invalid transaction type %d' and TxValidationCode_UNKNOWN_TX_TYPE. Only ENDORSER_TRANSACTION and CONFIG (and their processors) are typically registered.","triggerScenarios":"Passing a transaction envelope whose ChannelHeader.Type is 0 (unset), or a type like STATUS_UPDATE/PEER_RESOURCE_UPDATE that has no registered processor creator.","commonSituations":"Constructing test envelopes with a zero-valued ChannelHeader (Type defaults to 0); misconfigured system chaincode invocations; envelopes copied from a different network component with unexpected types.","solutions":["Set ChannelHeader.Type to the correct value (common.HeaderType_ENDORSER_TRANSACTION = 3 for normal invokes) before submitting.","Register a custom processor via NewProcessorFactory/ProcessorCreators if you intentionally support a new tx type.","In tests, use the peer's test helpers (e.g. txtestutils) that populate a valid type."],"exampleFix":"// before\nchdr := &common.ChannelHeader{ChannelId: \"mychannel\"}\n// after\nchdr := &common.ChannelHeader{ChannelId: \"mychannel\", Type: int32(common.HeaderType_ENDORSER_TRANSACTION)}","handlingStrategy":"validation","validationCode":"if common.HeaderType(chdr.Type) != common.HeaderType_ENDORSER_TRANSACTION && common.HeaderType(chdr.Type) != common.HeaderType_CONFIG { return fmt.Errorf(\"unsupported tx type %d\", chdr.Type) }","typeGuard":"func supportedTxType(t int32) bool { ht := common.HeaderType(t); return ht == common.HeaderType_ENDORSER_TRANSACTION || ht == common.HeaderType_CONFIG }","tryCatchPattern":"// caller of CreateProcessor\nproc, err := f.CreateProcessor(txEnv)\nvar ierr *tx.InvalidErr\nif errors.As(err, &ierr) && ierr.ValidationCode == peer.TxValidationCode_UNKNOWN_TX_TYPE {\n    // handle unknown tx type: skip/reject envelope\n}","preventionTips":["Always set ChannelHeader.Type explicitly; never rely on the zero value.","In tests, build envelopes with helpers that default to ENDORSER_TRANSACTION.","Keep processor registrations in one place so supported types are obvious."],"tags":["fabric","transaction-validation","processor-factory"],"backgroundTag":"unknown-transaction-type","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"}