Experience: programmers how to quickly locate problems (BUG)

I let the tears fall more than a memory leak

Every night I do not sleep more than you need

How long do you need to change tomorrow, clutching my hand

I am embarrassed that the fickle demands

Published in the middle of the night is always rollback always worry

Error (Bug) at any time of the storm drain plaguing my mind

As a programmer, these scenes you must have experienced. Today to talk about how to quickly locate the problem.

First draw the focus below is written by one of the words, I work with little experience and limited language skills, if badly written, but also look light spray. In addition, we are talking about are all on the back-end Java developer's point of view .

background

The following talk about the content, the analysis will be done, for example, to describe specific cases around the following true stories:

  • Case 1: App Home black and white.

    Detailed description: App, H5, home is a small program run by the same back-end interface is responsible for providing data. Test feedback chiefs said, App Home of black and white.

  • Case 2: commodity applet member price is displayed incorrectly.

    Description: Gangster test feedback, member price of a commodity is not displayed correctly, the client display member price is $ 0. Member price $ 0 Why is not correct? Because we have been restricted in the system, member price must be greater than 0.

  • Case 3: coupons can not receive, and pop shows "failure to receive the new coupon only to receive"!

    Description: This is a function to receive coupons. Users can receive coupons through the event. When users receive coupons page pop prompt: "Failed to receive the coupons only rookie to receive." At the same time, the test Gangster feedback that this account is a new account, was just registered users.

  • Case 4: A user purchases xx evaluation column evaluation lesson can not be opened.

    Description: evaluation column is a feature of our column, in this column, there is a review lesson. Evaluation lesson is to allow users to make online questions, the user first test, know your status. After the test is completed, the system will be based on the user's answer, we recommend the appropriate column curriculum to the user, for the user to learn.

Background account is completed, if it is you, in the face of these problems, how would you handle it?

Recurring problem

When testing chiefs feedback problems, first thing to do is to reproduce the problem . If the problem can reproduce, Okay, we have solved a half, and as a development, I think it must have this confidence. Can reproduce the problem, it must be able to repair (high and low repair costs, this is not within the scope of this article oh), it is not found Bug code, I can line debugging line thing! So, we have problems do not panic, calm calm.

What if the problem can not reproduce it? How to do?

This time, I was the general practice is to check the log . If an error message log, we will be able to quickly locate the specific code Bug where the error information . What if this time there is no error message? Ah ... I think about it, it seems no other way. The problem can not reproduce, the program not being given, it can only be more trouble Gangster test test to see if you can reproduce it.

Rapid positioning

After the previous step, we can already make Bug reproduced, and that the next step is to quickly locate. Rapid positioning? What positions?

General project development company, will divide the back-end development, front-end development, APP development, said here quickly locate, refers to quickly locate the end of the three which brought out a problem.

Then how to quickly locate it?

If you are familiar with the overall function of the process, what steps will clear the entire function experience, which module, which you to quickly locate the problem is very helpful. Of course, there are some monitoring tools can help developers quickly locate do to help developers understand the whole process. For example: sentry, skywalking and so on.

For Li :

Case 1: App Home black and white.

Case 2: The applet does not display the correct price of goods Member

These two issues feedback over time, I opened the app, H5, applets have looked and found: the only app home page black and white, H5 and Home applets are good, taking into account the App, H5, small Home program are provided by a back-end interface handles the same data, the probability of this problem is that a large app there's a problem, so please look at app development colleagues to help locate the problem.

The app, H5, small programs that have emerged in the three-terminal member price of goods displayed incorrectly this problem, so I concluded that this great probability is a logical question backend. Three-terminal codes are wrong to take the wrong Member this probability should be minimal.

Case 4: A user purchases xx evaluation column evaluation lesson can not be opened.

This is a problem online product feedback, referred to by Gangster test developed here when the test chiefs did not reproduce. Due to the special nature of the evaluation course, it needs to be done by the user title entered into the system, the system parses the user answer the case, then do the recommended system.

This is a typical associated with user behavior data problems that may only have a certain characteristic behaviors, user data will be encountered . Encounter this problem, it is very difficult to reproduce the test. You can check the log to see if there is no error message.

At that time encountered this problem, because of the project access to the sentry platform, the development here is the error of the received e-mail alert system abnormalities, very quick to find out why.

Positioning Interface

Well, after several rounds of largely determine the above, this is a high probability the backend Bug. Now we need to do is to quickly locate specific interfaces to the problem . If the mobile side, he grabbed a bag with Charles, H5 end directly open Chrome console.

so easy ~~ I can not find my mother no longer have to worry about interfaces friends ~ ~ Of course, in actual operation, it may not be so simple. Rendering a page may request distal plurality N interfaces.

For chestnuts

Case 2: commodity applet member price is displayed incorrectly.

Because the three-terminal app, H5, using a small program to get information about commodity same interface, I will give priority to the H5 platform debugging, after all, do not open Charles, convenient thing ~ ~

chrome console

Encounter problems, rapid response and resolution is the key, especially in the online issue. So sometimes this feature may not be your development, then how to find how to quickly locate specific interfaces so many requests it? It is up to your experience and understanding of the brain.

Here on a share my experience of it, may not be suitable for all scenarios. Take this case is: Open the product details page, open the console. Based on my understanding of the whole system, I'm sure there will be a return merchandise interfaces member price, I do not know which specific interfaces.

Well, this time how to do it? Guess Interface! Of course, not a quote. Members get goods price, and that the front-end interface to a high probability need to pass a back-end product id, product id that where? Product id usually appear in the URL of the current page's. Thus, (figure has been marked red) in the console box filter input product id. This time it can already filter out most of the requests.

The next thing you need to do is guess! Take a look at the rest of these requests address name, guess what his role; look at the field names returned interface, there is no name like "Member" field, there is no return value and member of the same front-end display field. Finally, after a bold guess, we have to do is to carefully verify, confirm our positioning interface is correct.

Location Code

After locating the interface, we're ready to look at the code, Bug repair it!

I do not know you have not encountered such a situation. Open the code, at first glance, this code is so long, but not before I write, how can I do it? Here we are speaking about how to quickly locate Bug code.

For chestnuts:

Case 2: commodity applet member price is displayed incorrectly.

After our meal before the fierce tiger's operations, and finally locate the problem.

//接口返回数据
{
    "price":9900,
    "discountPrice":8900,
    "vipPrice":0,
}

Member price is not displayed correctly, that is, "vipPrice":0the field in question.

Open the code and find the corresponding interface Controller, the Controller returns to find VO, VO find the vipPricesetter method field, the right mouse button find Usages. Congratulations, this time you've found the vipPricevalue of which line is to be set up, will focus on focus on this, Bug in the vicinity of this code. Look at this vipPricevalue is how calculated, calculation logic is not wrong.

If this time, unfortunately Controller of VO is through BeanUtilsthese tools will attribute mapping in the past, then you run find Usagesmight not find where the property is to be set up. Alas, by the time of writing the code cool, watery when things go wrong. You can only check the VO is where being used, and then went to check the code.

Case 3: Case 3: coupons can not receive, and pop shows "failure to receive the new coupon only to receive"!

If the "failure to receive the coupon newcomers receive only" this copy, you are returned to the client interface, then this time you have to do is, IDEA global find this keyword.

Code Search

Ha ha ha, congratulations, fast positioning, and in PayUserRuleCheckerline 51, it is not very simple?

Fix the problem

Now that you've targeted to a specific code, then the problem can be fixed. This time depends on personal experience in the matter, an experienced programmer could tell at a glance the problem.

Here are some points to note:

  • Learn to focus . The entire logic code service method may be many, but as "Member does not display correctly" This problem must be related to the sum calculated member price, you only need to focus on logic to this one.
  • Society Debug . In some cases, even if the code found the problem, but still I can not find the problem (for example, error logs say the first line xx have a problem, open the xx line look, ignorant, how could there be a problem yet). This time, you should try to debug the code, run-time debug through, data analysis, to find the problem.

How to avoid

Gangster test borrow the words: "No bug is not possible in this life is impossible without the bug."

And we have to do, it is necessary to minimize the Bug, to avoid recurring problems; second is to have problems, a quick fix. Do not be afraid Bug, not to worry about the Bug will not dare to write code.

A brief summary

Finally, the last, it is to be a brief summary:

  1. Have problems do not panic, as long as reproduction, will be able to repair

  2. Three-terminal APP, H5, a small program to quickly locate, find the person responsible for the problem

  3. Positioning of the interface, find the code in question

    • How quickly locate problem Interface
    • How quickly locate problems in your code
  4. debug then fix

  5. Sum up experience, to avoid repeating


Welcome to public concern number:

Coder black

Guess you like

Origin www.cnblogs.com/coderxiaohei/p/11722434.html