How to Handle Different Types of Errors in Hyper-ledger Fabric Blockchain

Blockchain isn’t the future — it’s now! Many industries and technology giants have started their ventures in blockchain technology and things will surely become bigger in the upcoming years. It’s also likely that you’ve started developing something based on the blockchain. We mean, if you are a coder who wants to keep track of the changes, you would have started with blockchain tech.
As it happens with development in other areas of technology, blockchain development is also prone to errors. You may have encountered a few such errors in the past. Thankfully, many blockchain development platforms now have dedicated methods for error handling and management. Hyperledger Fabric would be one of those options, you know.
Anyway, in this article, we will be talking about the different types of errors in blockchain development. Of course, they come in almost the same categories that you have seen in other programming languages. Major methods of handling these errors, however, is quite different when compared to normal coding. We’ll start with the different types of errors, then.
1. Network-based Errors
Network-based errors are quite common when it comes to blockchain development. At the core, blockchain is about one of the biggest networks in the world. Even the slightest network error can have an impact on how your blockchain-powered application is going to function in the real world. One of the easiest methods to avoid this is by ensuring the proper installation and starting of the network. You will have to take all the steps according to the network you have. Don’t worry, we have an example from Hyperledger Fabric here.
Example 1:
Error: Error trying to ping. Error: 2 UNKNOWN: make sure the chaincode test-registry has been successfully instantiated and try again: could not find chaincode with name ‘test-registry’
The error means that there is some constraint in connecting with the network. As we said earlier, you have to install the network properly. Once that’s done, you have to enter the following code for starting network activity.
- composer network install — card PeerAdmin@hlfv1 — archiveFile network-name@0.0.1.bna - composer network start — networkName networkname — networkVersion 0.0.1 — networkAdmin admin — networkAdminEnrollSecret adminpw — card PeerAdmin@hlfv1 — file networkadmin.card
2. Database Errors
As it goes without saying, the blockchain tech is based on some of the significant databases. During each line of code, data from different databases may be pulled and put to use. If you encounter database errors while coding for blockchain, you should be much alarmed, you know. The first step is to make sure that there are no corruptions in the database set. Next step, you need to ensure the proper connection between the system and the data.
Example:
[ERROR] pgservice - [INSERT ERROR] - index row requires 291056 bytes, maximum size is 8191
It deals with some of the issues in the database. The system was not able to interact with the same. One of the common fixes for the issue was:
By dropping the index (transaction_chaincode_proposal_input_idx) on the table transactions. You could use the following script for doing this:
CREATE INDEX transaction_chaincode_proposal_input_idx ON transactions USING btree (chaincode_proposal_input COLLATE pg_catalog."default");
3. HTTP/API Errors
As the name says, these errors occur when there is something wrong with the server connection or the API that is being used. Depending on the type of error that occurs, certain codes are given for each type. In the world of the world wide web, for instance, HTTP Error 404 means that the page has not been found. Similarly, it is possible to find other types of errors in blockchain development as well.
Example 1:
Error: Network Not found issue
As you can see, the system cannot find the network, which is causing the error. In order to fix this,
You will have to visit ./peer-base.yaml and make changes to the entry named,
CORE_VM_DOCKER_HOSTCONFIG_NETWORKMODE
After this, you will have to clean the docker containers. Once you are done, you can go ahead and rebuild.
Example 2:
Error: readBlock -> DEBU 00a Got status: &{FORBIDDEN} Error: can’t read the block: &{FORBIDDEN}
This error is observed when there is something wrong with the provided permissions. Also, there may be conflicts between two containers.
The solution is to kill the containers and restart.
4. Runtime Errors
You would also have come across runtime errors while dealing with Hyperledger or other types of blockchain development tech. The fact about this type of errors is that you can find a huge number of them, regardless of the coding framework that you are using. If you see one of these errors, it means that there is something wrong with the process of runtime.
Example 1:
Error: Connection fails: Error: Error trying to ping. Error: Composer runtime (0.19.8) is not compatible with client (0.19.5)
It will be retried for the next request.
The probable solution for this error would be the following:
./stopFabric.sh npm install -g composer-playground@0.19.8 composer-rest-server
Example 2:
ERROR: network composer_default id b1067bdec4ca1800510fc9cc1f5d3500736e48920693b03831df0d8d8472ffac has active endpoints
This error normally occurs when you are trying to run two fabric servers at the same time. That is, you might have started the new fabric server without actually turning the first one off.
The solution, the simple one, is to turn off the earlier server and continue with the newer one.
Error Handling in Blockchain Frameworks
Let’s take the case of IBM Cloud Code, for instance.
There are in-built options to set up throwing and catching errors by default. This will make it really easy for a coder to understand and represent the potential errors in the system. The best part is that the performance of the API will not be affected by this.
Similarly, coming to the latest release of Hyperledger Fabric Code, it has a specific set of codes for displaying error codes. There is a vendor package that is used for generation and display of the errors. Since the docs are available for access, understanding and implementing the changes are also easy.
The Bottom Line
Apparently, these are the major types of errors that you would find in the Blockchain. As we said earlier, there is some error handling tech in frameworks. As a programmer, you should know about these errors and try your best to clean the code — so that these errors don’t occur.
