How to find a rare mistake?

My application contains an error that causes the script to work indefinitely. When I make the script stop, all jQuery user interface elements do not respond to my actions, nor do applications respond to keystrokes.

If I decide to open Firebug, it requires a page reload, and all the current state of the application is lost.

The fact is that I can not reproduce this error, and it drove me a little crazy. How to find and fix such a spotty mistake?

UPDATE. Thank you all for your advice. But the problem is that I cannot understand when the error occurs, and therefore cannot reproduce it. That is why standard procedures will not work in my case.

I looked at all the calls to the loop and recursive functions, but haven't figured out the problem yet.

Publishing code is not a good idea. The list of codes is huge and rather complicated (game).

POSSIBLE SOLUTION. . I will follow one of the posted tips and try to combine all the functions that might cause the problem. Hope this helps.

+6
source share
6 answers

Endless long time means

I think some function is called recursive, or some event is firing recursively. To track him

  • Try putting console.log in all the functions called from window.onload or document.ready (if you are using jquery).
  • Use the Firebug profile , which will tell you about each function call.
0
source

There are two main approaches to solving this issue:

  • Set breakpoints and execute your code
  • Start commenting on specific sections of code. After you comment on the section that fixes the error, start commenting on the small fragments of this section until you come to the line of code that causes the problem.

It may also help to find out what you are looking for. An infinitely working script will usually be the result of one of two things:

  • A cycle that never ends.
  • Function that calls itself

Keeping track of these things can help the debugging process go a little faster. Good luck

+6
source
  • Break the code into pieces and determine which one is causing the failure. for example, if you have a form with several fields that have date picker and autocompletion mechanisms, separate them one by one. Zero-on, who is calling him.

  • use the debugger timeline. cruise around your site with a schedule to record your page. You will see on the timeline which task it takes too long. The browser may crash when you find the error, but you will at least see what happened when.

  • try to recreate your actions. Take a few step-by-step checklists about how you move. that way, you can trace in the code the possible path that your script took when you made your move. if JS had reverse traffic like PHP, it would be easier.

  • try to see your code. things like loops, recursions, or even two functions calling each other can cause this infinite loop.

  • if possible, use a VCS tool such as SVN or GIT. you can easily build n 'to break your code without fear of losing the working version. You can easily come back if you use VCS.

+2
source

I am always looking for functions that can be called too often or loops that never end a loop. Then track how many times your suspicious functions / loops have been executed. Example:

  var runCount = 0; function guiltyLookingFunction(params) { runCount++; //increase by 1 every time this function runs if (runCount>1000) //if this has run some insane number of times alert("this function is the that running wild!"); //the rest of your function code //same thing with loops within functions: var loopCount = 0; while (0!=1) //this will always be true, so the loop won't stop! { loopCount++; if (loopCount>1000) alert("this loop is to blame!"); //the rest of your loop } } 

(replace "this function / loop" with a specific identifier if you follow a few suspects)

0
source

A) Use WebKit inspector (Safari, Chrome, Chromium) instead of firebug - don’t download anymore, yay!

B) Set some debugging output along the way that will help narrow the problem down to the executor.

0
source

Firebug Reloading? Have you tried to open Firebug download before ?

0
source

Source: https://habr.com/ru/post/910435/


All Articles