{"record":{"id":"a638c8bfd26f7b8a","repo":"hyperledger/fabric","slug":"unknown-operation-type","errorCode":null,"errorMessage":"unknown operation type","messagePattern":"unknown operation type","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/handler.go","lineNumber":1331,"sourceCode":"\t\t\tif err = h.purgePrivateData(delState, txContext, msg.ChannelId); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\tcase pb.WriteRecord_PUT_STATE_METADATA:\n\t\t\tputStateMetadata := &pb.PutStateMetadata{\n\t\t\t\tKey:        kv.GetKey(),\n\t\t\t\tCollection: kv.GetCollection(),\n\t\t\t\tMetadata: &pb.StateMetadata{\n\t\t\t\t\tMetakey: kv.GetMetadata().GetMetakey(),\n\t\t\t\t\tValue:   kv.GetMetadata().GetValue(),\n\t\t\t\t},\n\t\t\t}\n\t\t\tif err = h.putStateMetadata(putStateMetadata, txContext, msg.ChannelId); err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\n\t\tdefault:\n\t\t\treturn nil, errors.New(\"unknown operation type\")\n\t\t}\n\t}\n\n\treturn &pb.ChaincodeMessage{Type: pb.ChaincodeMessage_RESPONSE, Txid: msg.Txid, ChannelId: msg.ChannelId}, nil\n}\n\n// Handles requests that modify ledger state\nfunc (h *Handler) HandleInvokeChaincode(msg *pb.ChaincodeMessage, txContext *TransactionContext) (*pb.ChaincodeMessage, error) {\n\tchaincodeLogger.Debugf(\"[%s] C-call-C\", shorttxid(msg.Txid))\n\n\tchaincodeSpec := &pb.ChaincodeSpec{}\n\terr := proto.Unmarshal(msg.Payload, chaincodeSpec)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"unmarshal failed\")\n\t}\n\n\t// Get the chaincodeID to invoke. The chaincodeID to be called may\n\t// contain composite info like \"chaincode-name:version/channel-name\".","sourceCodeStart":1313,"sourceCodeEnd":1349,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/handler.go#L1313-L1349","documentation":"HandleWriteBatch iterates over records in a WriteBatchState and switches on each record's Type (PUT_STATE, PUT_STATE_METADATA, etc.). A record whose type is not one of the known operation types hits the default branch and produces this error. It means the batch contains an unrecognized/unsupported write operation.","triggerScenarios":"A write batch containing a pb.WriteRecord with an unset or future/unknown Type value — e.g. a newer peer or shim emitting an operation type this handler version does not know, or a zero-valued WriteRecord that was never given a type.","commonSituations":"Version skew between peer and chaincode shim where a new batch operation type was added; custom shims constructing WriteRecord without setting Type; corrupted batch assembly that omits the type field.","solutions":["Align peer and chaincode shim versions so all WriteRecord types are supported","Make sure every WriteRecord added to the batch explicitly sets its Type field before sending","Update fabric to a version where the new operation type is handled in HandleWriteBatch"],"exampleFix":"// before\nrec := &pb.WriteRecord{Key: key, Value: value} // Type unset\n\n// after\nrec := &pb.WriteRecord{Type: pb.WriteRecord_PUT_STATE, Key: key, Value: value}","handlingStrategy":"validation","validationCode":"func validWriteType(t pb.WriteRecord_Type) bool {\n\tswitch t {\n\tcase pb.WriteRecord_PUT_STATE, pb.WriteRecord_PUT_STATE_METADATA:\n\t\treturn true\n\t}\n\treturn false\n}\n// validate each record before adding to the batch","typeGuard":"func isKnownWriteRecord(kv *pb.WriteRecord) bool {\n\treturn kv.GetType() == pb.WriteRecord_PUT_STATE ||\n\t\tkv.GetType() == pb.WriteRecord_PUT_STATE_METADATA\n}","tryCatchPattern":"resp, err := handler.HandleWriteBatch(msg, txContext)\nif err != nil {\n\tif strings.Contains(err.Error(), \"unknown operation type\") {\n\t\t// drop or quarantine the offending record; version-skew likely\n\t\treturn handleVersionSkew(msg)\n\t}\n\treturn err\n}","preventionTips":["Explicitly set the Type field on every pb.WriteRecord","Upgrade peer and shim together so new WriteRecord types are understood by both","Add unit tests covering every operation type included in write batches"],"tags":["fabric","chaincode","protobuf","write-batch"],"backgroundTag":"unknown-write-operation-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"}