It’s not just memory leaks that bring tears to my eyes

It’s not just your needs that keep me up at night

How long will it be tomorrow? You held my hand

What puzzles me is the fickle demands

Releases that always roll back in the middle of the night are a permanent worry

Bugs plague me at any time

As a programmer, you must have experienced all of these scenarios. Today we’re going to talk about how to quickly locate a problem.

First draw the key point, the following are all one’s own words, I work experience is not much, language expression ability is limited, if the writing is not good, also hope to spray. In addition, this article is all about the perspective of a Java backend developer.

background

The following content will focus on the following real cases for example analysis, and first describe specific cases:

  • Case 1: The App home page is blank.

    – App, H5, small program home page are by the same backend interface responsible for providing data. Test boss feedback, App home screen blank.

  • Case 2: The membership price of small program goods is displayed incorrectly.

    -Test boss feedback, a commodity member price display is not correct, the client display member price is 0 yuan. Why is a membership price of $0 incorrect? Because we have made a limit in the system, the membership price must be greater than 0 yuan.

  • Case 3: The coupon can not be picked up, the popup window shows “failed to pick up, the coupon is only for new people to pick up”!

    Description: This is a coupon collection function. Users can collect coupons through the event. When the user gets the coupon, the page pops up with a prompt: “Failed to get the coupon, this coupon is only for new people to get”. At the same time, the test boss feedback said that this account is a new account, is just registered users.

  • Case 4: The evaluation course of xx evaluation column purchased by a user cannot be opened.

    The evaluation column is a special column of our company. In this column, there is an evaluation class. The evaluation class allows users to take online test questions, and users take the test first to understand their status. After the test is completed, the system will recommend the appropriate class schedule for users to learn according to their answers.

The background explained, that if you, in the encounter with these problems, how will deal with it?

Recurring problems

When the test leader reports a problem, the first thing to do is to reproduce the problem. If the problem can recur, well, we’ve solved most of it, and as a developer, I think we should have that confidence. If the problem can be repeated, it must be fixed (the repair cost is high or low, which is not discussed in this article), it is really not found Bug code, I can debug line by line! So don’t panic when you have a problem.

What if the problem doesn’t recur? How to do?

At this point, my usual practice is to check the log. If there is an error message in the log, it can be used to quickly locate the specific code where the Bug is. What if there’s no error message at this point? B: well… Let me see. I don’t think there’s any other way. The problem can not reproduce, the program did not report an error, that can only trouble test big guy to test again, see if it can reproduce.

Rapid positioning

After the previous step, we can reproduce the Bug, so the next step is to quickly locate. Quick fix? To what?

General company project development, will be divided into back-end development, front-end development, APP development, fast positioning here refers to the rapid positioning of the three ends of which is the problem.

So how do you locate it quickly?

If you are familiar with the overall flow of the feature and know what steps and modules the feature will go through, it will be very helpful to locate problems quickly. Of course, there are monitoring tools available to help developers quickly locate and understand the process. Examples: Sentry, Skywalking, etc.

Take a chestnut:

Case 1: The App home page is blank.

Case 2: The membership price of small program goods is displayed incorrectly

When these two problems came back to me, I opened app, H5 and mini program, and found that: Only the home page of APP has a blank screen, and the home page of H5 and small program are all good. Considering that the same back-end interface is responsible for providing data on the home page of APP, H5 and small program, this problem is most likely to be the problem of APP, so PLEASE ask app developer colleagues to help locate the problem.

However, the incorrect display of product membership price appeared in app, H5 and small program, so I concluded that this was probably a logic problem at the back end. I don’t think the probability of writing the wrong code on all three ends and getting the wrong membership price is very high.

Case 4: The evaluation course of xx evaluation column purchased by a user cannot be opened.

This is an online problem with product feedback that was mentioned to the development side by the test leader, who was not able to reproduce it at the time. Due to the particularity of the evaluation course, it needs users to do the questions and input them into the system. The system analyzes the answers of users and then makes system recommendations.

This is a typical problem related to user behavior data, and may only be encountered by users with certain characteristic behaviors and data. Testing is also difficult to replicate with this problem. You can check the log to see if there are any error messages.

When I encountered this problem, because the project was connected to the Sentry platform, the development side also received an email reminding of system abnormality, and I found the cause very quickly.

Positioning interface

Well, based on the previous rounds, this is probably a backend Bug. Now all we need to do is quickly locate the specific interface where the problem occurred. On mobile, grab a package with Charles, and open the Chrome console directly on H5.

So easy~~ Mom no longer need to worry that I can not find the interface ~~ of course, in the actual operation process, may not be so simple. The front-end rendering page may request N more interfaces.

For chestnuts

Case 2: The membership price of small program goods is displayed incorrectly.

Because app, H5 and small program use the same interface to obtain information related to goods, I will debug on H5 platform first. After all, Charles is not required, which is convenient ~~

When you encounter problems, quick response and solution is key, especially online problems. So sometimes you may not have developed this feature, so how do you quickly locate a specific interface in so many requests? It comes down to experience and a good brain.

Here is one of my experiences that may not be suitable for all scenarios. Take this example: open the product details page, open the console. Based on my overall understanding of the system, I’m sure there will be an interface that returns the membership price of the item. I don’t know which interface.

Okay, so what do we do at this point? Guess interface! Of course, it’s not a wild guess. To obtain the product membership price, the interface probably needs to pass a product ID from the front end to the back end. Where is the product ID? The item ID usually appears in the URL of the current page. Enter the item ID in the Console filter box (highlighted in red). At this point you can filter out most of the requests.

Next thing you know, guess! Look at the rest of the requested address names and guess what it does; See if the interface returns a field with a name like the “membership price” field, and if the return value is the same as the membership price displayed on the front end. Finally, after making a bold guess, all we need to do is carefully verify that we have located the right interface.

Location code

Once the interface is located, we are ready to look at the code and fix the bugs!

I don’t know if you’ve ever been in that situation. I open up the code, and I look at it, and it’s long, and I didn’t write it before, so what do I do? Here’s how to quickly locate Bug code.

For chestnut:

Case 2: The membership price of small program goods is displayed incorrectly.

After our previous aggressive operation, we finally located the problem.

{"price":9900, "discountPrice":8900, "vipPrice":0,}Copy the code

The membership price is not displayed correctly, i.e. “vipPrice”:0 this field is not correct.

Open the code, find the Controller corresponding to this interface, find the VO returned by this Controller, find the setter method for the vipPrice field in VO, right-click Find Lead. Congratulations, at this point you have found the line on which the value of vipPrice is set, just focus on that, the Bug is somewhere in the code. Let’s see how the value of vipPrice is calculated, if the calculation logic is wrong.

If at this point, unfortunately Controller’s VO is mapping properties past through some utility class like BeanUtils, then you might run Find Lead and not find where the properties were set. Oh, good for writing code, and tearful when things go wrong. The only way to find VO is to find where it is used, and then go to the code to find.

Case 3: Case 3: The coupon can not be received, the popup window shows “failed to receive, the coupon is only for new people to receive”!

If the text “failed to claim, the coupon is only for new people to claim” is returned by your interface to the client, then, this time you need to do is, IDEA global search for this keyword.

Ha ha ha, congratulations, quick location, line 51 of PayUserRuleChecker, isn’t that easy?

To fix the problem

Now that you’ve located the specific code, you’re ready to fix the problem. This is a matter of personal experience, and experienced programmers can probably spot a problem when they see one.

Here are some things to watch out for:

  • Learn to focus. The logic of the entire service method can be a lot of code, but problems like “the membership price is not displayed correctly” must be related to calculating the membership price, you just need to focus on this piece of logic.
  • Learn to debug. In some cases, the problem is not found even when the code is found (for example, the error log says that line XX has a problem, open line XX and look at it, meng, how could there be a problem here). At this point, you should try to debug the code by analyzing the data at runtime to find problems.

How to avoid

To borrow a phrase from the testing gurus: “It’s impossible to be bug-free, and you’ll never be bug-free.”

What we need to do is, first, reduce bugs as much as possible to avoid repeated problems; Two is to encounter problems, quick repair. Don’t be afraid of bugs, and don’t be afraid to write code for bugs.

Simple summary

Finally, to conclude briefly:

  1. Don’t panic when you encounter a problem. As long as you can reproduce it, you can fix it

  2. APP, H5, small program three quick positioning, find the problem responsible person

  3. Locate the problem interface and find the problem code

    • How can I quickly locate faulty interfaces
    • How to quickly locate problem code
  4. debug then fix

  5. Learn from experience and avoid repeat offenses


Welcome to our official account: