<commit_before>#Marbles Debug Help

So you think marbles is totally broken, nothing is working right and this whole thing is lame. 
I can at least assure you that marbles is not broken. 
Let’s start at the very beginning and check things off one by one. 

**Game Plan**

1. [Check if the network is showing signs of life](./#step1)
1. [Check if the marbles app is registering users for the permissioned network](./#step2)
1. [Check if marbles is deploying chaincode successfully](./#step3)
1. [Check if marbles backend is reaching chaincode functions](./#step4)
1. [Check if marbles frontend is sending its actions](./#step5)
1. [Turn it off and back on again](./#step6)

**[ Step 1 ]**<a name="step1"></a>

We need to first check off that your network is running correctly. 
The best way to do this is to open your networks monitor page. 
What we want to see is 2 peers (validating peer 1 and 2) and a CA with the status of "running" or "up for x time". 
What we do not want to see is missing peers, or peers with an "exited" status. 
Follow the instructions in [this section](#Peer-or-ChainCode-Logs) to get to the monitor page, and while you are there check the peer logs to see if there is anything suspicious.

Results:

- *Everything looks okay*
	- Great, meet me at step 2
- *Anything else*
	- You should delete this network and create another one. if this happens multiple times you should contact us
	
	
**[ Step 2 ]**<a name="step2"></a>

Right so next is to verify if the marbles app is registering secure context users or not. 
To do this we need to take a look at the logs from node.js. 
Depending on your marble setup you either need to get to your [Bluemix Node.js Logs](#Bluemix-Node.js-Logs) or your [Local Machine Node.js Logs](#Local-Machine-Node.js-Logs). 

Now that you have access to your logs let’s find the relevant logs for user registration. 
The SDK will print messages similar to the ones below to the console:
	
	[ibc-js] Peer:  vp1-3a82c724-6934-4575-87d8-047eefdcf25d_vp1-api.blockchain.ibm.com:80
	[ibc-js] Peer:  vp2-3a82c724-6934-4575-87d8-047eefdcf25d_vp2-api.blockchain.ibm.com:80
	[ibc-js] Registering  vp1-3a82c724-6934-4575-87d8-047eefdcf25d_vp1-api.blockchain.ibm.com:80  w/enrollID - user_type1_3fe7935193
	[ibc-js] Registering  vp2-3a82c724-6934-4575-87d8-047eefdcf25d_vp2-api.blockchain.ibm.com:80  w/enrollID - user_type1_0c8e9f05b2
	[ibc-js] Registration success: user_type1_0c8e9f05b2
	[ibc-js] Registration success: user_type1_3fe7935193

Ideally your logs look like mine above. 
They may be spaced differently by having other lines in between these ones.

Results:

- *I have registration failure message(s)*
	- Nuts, so here are a few issues that may cause this:
		- You fed it incorrect usernames and/or secrets. Verify if the username printed out correctly matches one from your services credentials list
		- You fed it incorrect peer host/ports. Verify the hostname/ports are the same as the ones you see in your network's monitor page.
		- Verify if your peers are still running (we did this in step 1 though...)
		- You have previously registered this username to a different peer. This is not allowed. A username can only be registered against 1 peer. (re-registering a username against the same peer is fine though)
		- You must have at least one registered username for marbles. If only one works edit the list of peers/users you feed marbles to only contain this one.
		- Check the [logs for CA](#Peer-or-ChainCode-Logs) for any clues (same instructions as peer logs)
		- If nothing is working, delete this network and create another
- *I don't see any registration messages at all*
	- So either you did not feed `ibc.load()` any usernames or you did not feed it any appropriate usernames. An apporiate username is one that contains "type_1" in the name. Any other names get filtered out by `ibc.load`.
		- If this is problematic for you (ie you have a custom IBM Blockchain Network) then you need to build a custom `ibc.load()` out of the other SDK functions. `ibc.load()` purpose is to make deploying to standard IBM Blockchain Networks easy. If you have a custom network you should create your own function that mimics `ibc.load()` (tear it apart and look at it!). You would only need to omit `filter_users()`, and possibly change what users/peer relation you want with your own calls to `ibc.register()`.
- *Everything looks okay*
	- Glad to hear it, lets go to step 3
	
	
**[ Step 3 ]**<a name="step3"></a>

Next we want to see if the marbles app deployed its chaincode successfully. 
The first place I'd look is in the networks monitor page. 
Follow the instructions in [this section](#Peer-or-ChainCode-Logs) to get to the monitor page. 

Check the bottom table. 
Does it have a row with a chaincode hash? 
If it does you can probably go to step 4.
If it does not then we should look at the logs for your node app again. 
Even if it the chaincode row is present you may still want to verify the deploy logs from your node app.
What we are looking for is: 
	
	[ibc-js] Deploying Chaincode - Starting
	[ibc-js]        function: init , arg: [ 'abc', '99']


			Waiting...
			deploy success [wait 1 more minute]
	[ibc-js] Deploying Chaincode - Complete

Its not important if the arguments in the init function do not match mine. 
Though it is important that your deploy function tried to call some function that does exist in your chaincode. 
If you see "function: undefined, arg: undefined" you have not specified a function to be called on deploy which is out of spec. 
What you do want to match is the success message at the bottom. 
You may find that the sdk did not even attempt to deploy and a failure happened before it got to that point. 

Results:

- *I see a failure/error messages before deploy even happens*
	- First off try to make sense of the specific error that was also printed.
	- If you see anything like "fs readdir Error" check the  `unzip_dir` and `zip_url` field in the options objefct you passed to `ibc.load()`. To do this manually download the git repo using the `options.chaincode.zip_url` then extract it.  The `gir_dir` var should be the exact relative path to get to the desired cc folder
	- This is likely some sort of node.js error and has nothing to do with the blockchain Network.  Try StackOverflow and Google to figure it out.
- *I see a deploy failure messages*
	- There could be many causes for this. 
		- First off try to make sense of the specific error that was also printed.
		- If you see anyhing like "error code 2" then your chaincode has build issues and cannot be compiled. Manually build your chaincode and look at the compiler errors.
		- If you see antyhing like "401 unauthorized" message then you have not passed it a secure context username that has been successfully registered. (we did this in step 2 though)
		- You fed it incorrect peer host/ports. Verify the hostname/ports are the same as the ones you see in your network's monitor page.
		- Verify if your peers are still running (we did this in step 1 though...)
		- Check the [logs for the peer](#Peer-or-ChainCode-Logs) for any clues, you are probably deploying to peer 1.
		- If nothing is working, delete this network and create another
- *Everything looks okay*
	- Wohoo, let’s go to step 4
<commit_msg>- fixe links<commit_after>#Marbles Debug Help

So you think marbles is totally broken, nothing is working right and this whole thing is lame. 
I can at least assure you that marbles is not broken. 
Let’s start at the very beginning and check things off one by one. 

**Game Plan**

1. [Check if the network is showing signs of life](./i_lost_my_marbles.md#step1)
1. [Check if the marbles app is registering users for the permissioned network](./i_lost_my_marbles.md#step2)
1. [Check if marbles is deploying chaincode successfully](./i_lost_my_marbles.md#step3)
1. [Check if marbles backend is reaching chaincode functions](./i_lost_my_marbles.md#step4)
1. [Check if marbles frontend is sending its actions](./i_lost_my_marbles.md#step5)
1. [Turn it off and back on again](./i_lost_my_marbles.md#step6)

**[ Step 1 ]**<a name="step1"></a>

We need to first check off that your network is running correctly. 
The best way to do this is to open your networks monitor page. 
What we want to see is 2 peers (validating peer 1 and 2) and a CA with the status of "running" or "up for x time". 
What we do not want to see is missing peers, or peers with an "exited" status. 
Follow the instructions in [this section](#peer-or-chaincode-logs) to get to the monitor page, and while you are there check the peer logs to see if there is anything suspicious.

Results:

- *Everything looks okay*
	- Great, meet me at step 2
- *Anything else*
	- You should delete this network and create another one. if this happens multiple times you should contact us
	
	
**[ Step 2 ]**<a name="step2"></a>

Right so next is to verify if the marbles app is registering secure context users or not. 
To do this we need to take a look at the logs from node.js. 
Depending on your marble setup you either need to get to your [Bluemix Node.js Logs](#bluemix-node.js-logs) or your [Local Machine Node.js Logs](#local-machine-node.js-logs). 

Now that you have access to your logs let’s find the relevant logs for user registration. 
The SDK will print messages similar to the ones below to the console:
	
	[ibc-js] Peer:  vp1-3a82c724-6934-4575-87d8-047eefdcf25d_vp1-api.blockchain.ibm.com:80
	[ibc-js] Peer:  vp2-3a82c724-6934-4575-87d8-047eefdcf25d_vp2-api.blockchain.ibm.com:80
	[ibc-js] Registering  vp1-3a82c724-6934-4575-87d8-047eefdcf25d_vp1-api.blockchain.ibm.com:80  w/enrollID - user_type1_3fe7935193
	[ibc-js] Registering  vp2-3a82c724-6934-4575-87d8-047eefdcf25d_vp2-api.blockchain.ibm.com:80  w/enrollID - user_type1_0c8e9f05b2
	[ibc-js] Registration success: user_type1_0c8e9f05b2
	[ibc-js] Registration success: user_type1_3fe7935193

Ideally your logs look like mine above. 
They may be spaced differently by having other lines in between these ones.

Results:

- *I have registration failure message(s)*
	- Nuts, so here are a few issues that may cause this:
		- You fed it incorrect usernames and/or secrets. Verify if the username printed out correctly matches one from your services credentials list
		- You fed it incorrect peer host/ports. Verify the hostname/ports are the same as the ones you see in your network's monitor page.
		- Verify if your peers are still running (we did this in step 1 though...)
		- You have previously registered this username to a different peer. This is not allowed. A username can only be registered against 1 peer. (re-registering a username against the same peer is fine though)
		- You must have at least one registered username for marbles. If only one works edit the list of peers/users you feed marbles to only contain this one.
		- Check the [logs for CA](#peer-or-chaincode-logs) for any clues (same instructions as peer logs)
		- If nothing is working, delete this network and create another
- *I don't see any registration messages at all*
	- So either you did not feed `ibc.load()` any usernames or you did not feed it any appropriate usernames. An apporiate username is one that contains "type_1" in the name. Any other names get filtered out by `ibc.load`.
		- If this is problematic for you (ie you have a custom IBM Blockchain Network) then you need to build a custom `ibc.load()` out of the other SDK functions. `ibc.load()` purpose is to make deploying to standard IBM Blockchain Networks easy. If you have a custom network you should create your own function that mimics `ibc.load()` (tear it apart and look at it!). You would only need to omit `filter_users()`, and possibly change what users/peer relation you want with your own calls to `ibc.register()`.
- *Everything looks okay*
	- Glad to hear it, lets go to step 3
	
	
**[ Step 3 ]**<a name="step3"></a>

Next we want to see if the marbles app deployed its chaincode successfully. 
The first place I'd look is in the networks monitor page. 
Follow the instructions in [this section](#peer-or-chaincode-logs) to get to the monitor page. 

Check the bottom table. 
Does it have a row with a chaincode hash? 
If it does you can probably go to step 4.
If it does not then we should look at the logs for your node app again. 
Even if it the chaincode row is present you may still want to verify the deploy logs from your node app.
What we are looking for is: 
	
	[ibc-js] Deploying Chaincode - Starting
	[ibc-js]        function: init , arg: [ 'abc', '99']


			Waiting...
			deploy success [wait 1 more minute]
	[ibc-js] Deploying Chaincode - Complete

Its not important if the arguments in the init function do not match mine. 
Though it is important that your deploy function tried to call some function that does exist in your chaincode. 
If you see "function: undefined, arg: undefined" you have not specified a function to be called on deploy which is out of spec. 
What you do want to match is the success message at the bottom. 
You may find that the sdk did not even attempt to deploy and a failure happened before it got to that point. 

Results:

- *I see a failure/error messages before deploy even happens*
	- First off try to make sense of the specific error that was also printed.
	- If you see anything like "fs readdir Error" check the  `unzip_dir` and `zip_url` field in the options objefct you passed to `ibc.load()`. To do this manually download the git repo using the `options.chaincode.zip_url` then extract it.  The `gir_dir` var should be the exact relative path to get to the desired cc folder
	- This is likely some sort of node.js error and has nothing to do with the blockchain Network.  Try StackOverflow and Google to figure it out.
- *I see a deploy failure messages*
	- There could be many causes for this. 
		- First off try to make sense of the specific error that was also printed.
		- If you see anyhing like "error code 2" then your chaincode has build issues and cannot be compiled. Manually build your chaincode and look at the compiler errors.
		- If you see antyhing like "401 unauthorized" message then you have not passed it a secure context username that has been successfully registered. (we did this in step 2 though)
		- You fed it incorrect peer host/ports. Verify the hostname/ports are the same as the ones you see in your network's monitor page.
		- Verify if your peers are still running (we did this in step 1 though...)
		- Check the [logs for the peer](#peer-or-chaincode-logs) for any clues, you are probably deploying to peer 1.
		- If nothing is working, delete this network and create another
- *Everything looks okay*
	- Wohoo, let’s go to step 4

{'fraction_non_alphanumeric': 0.06478642959329654, 'fraction_numerical': 0.02370733701205804, 'mean_word_length': 3.8384970336189848, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2716743', 'n_tokens_mistral': 4520, 'n_tokens_neox': 4212, 'n_words': 2270}