In order to better assist you to locate difficult bug problems, here summed up some of my experience to you, I hope to help you

For simple bugs, we can easily locate and solve them, but for difficult and complex bugs, we can divide them into five core process methods, including: combing process, log analysis, minimum path, guess elimination, and independent verification.

Minimum path

After encountering a problem, learn the minimum path for reoccurrence of the problem immediately and determine the severity and impact level of the problem based on the minimum path. If the reproduction path is complex, the impact should be small; if the reproduction path is simple, the impact should be large and must be resolved as soon as possible.

Carding process

Don’t think you know your own code logic, often too familiar but lost the details. Before encountering difficult diseases, we must reproduce and comb the logical process, draw the corresponding logical flow diagram, and reproduce and comb it again according to the business logic. This helps you locate problems faster. If you feel trouble, you can directly use brain map to draw, more simple and fast. Like this

Log analysis

When some service exceptions occur, you need to add logs to help locate faults. You only need to add logs at logical forks and external calls. Such as if else, catch, interface calls, SDK calls, and so on. The pseudocode below, for example, adds various log messages to check for problems.

if(! id){ log.info('id is not exist');
  return -1;
}
let mainInfo = api.get('main-info');
if(! mainInfo){ log.error('get main info come out error, pls check');
   return -2;
}
let picList = api.get('pic-list');
if(! picList){ log.error('get pic list come out error, pls check');
}
let commentList = api.get('comment-list');
if(! commentList){ log.error('get comment list come out error, pls check');
}
return mainInfo;
Copy the code

Guess out

When you encounter a problem, make a bold guess. You should assume that anything could go wrong, such as third-party libraries, system calls, etc., and don’t list all the possible scenarios with the idea that there will be no problem.

Guess point Guess that The authentication
For loop exception An abnormal exit is thrown midway
The SDK call returned an exception The Facebook return interface is abnormal. Procedure
Error obtaining system API Obtaining location information The system does not update location information in a timely manner because of caching

Independent verification

Once you have a list of guesses, verify them one by one. It is important to note that all the validations must be independent, not multiple validations at the same time.

If you encounter problems that cannot be reproduced, the minimum reproduction path cannot be found because the impact surface is controllable. Therefore, you only need to add logs to enhance positioning assistance judgment, and strengthen follow-up for core important modules.