Playback foreground error

So, I'm working on a project as an intern who uses Bugsnag to catch bugs in his web application. There is one error I am trying to fix, I cannot reproduce. This only affects 2 people out of all of our customers using the product. I did not write this code, I am only trying to fix the error. An error TypeErrorยทUncaught TypeError: Cannot set property 'selected' of undefined

, and it is in this function on the second line.

function selectInstaller(installer) {
      installers[installer.id].selected = true;
      selectedInstaller[installer.id] = installer;
}

      

It is assumed that a list of people exists and the user can select a person to display events on the calendar for that particular person. After selecting a user, this function is called.

function handleSelectInstaller(event) {
      var $btn = $(this);
      var $li = $btn.closest('li');
      $li.toggleClass('active');
      var installerAttributes = $btn.closest('li').data();
      if($li.hasClass('active')) {
        selectInstaller(installerAttributes);
        fetchInstallerCalendar();
      } else {
        previousInstallerCount = Object.keys(selectedInstaller).length;
        unselectInstaller(installerAttributes);
        syncView();
      }
    }

      

As you can see, the handleSelectInstaller function calls the selectInstaller function, which then raises an error. As I said, this is a rare situation where an error occurs and I can't see how to reproduce the error. I thought that maybe something might be wrong with the database for this particular person, but my manager looked at it and he said it looked right. He also tried to log into a user account and try to reproduce it that way, and he gave him no problem (so he couldn't reproduce it on his computer). But Bugsnag still reports this when the user logs on to their computer. Any ideas on how I can reproduce this error so that I can fix this issue? Or could it be completely out of my control?

EDIT : Here's what gets called on page load. The latter function will automatically select the user who is logged in. Then, when the user (installer) selects or deselects their name, the handleSelectInstaller function is called. The structure shows that we are passing to the handleSelectInstaller function.

function init(options) {
      var options = options || {};
      baseUrl = serverpath + "v1.0/calendar_events";
      selector = options.selector || '#calendar';
      colors = {
        default: '#59595C',
        disabled: '#ff9f89'
      };
      dateFormat = 'YYYY-MM-DD';
      type = $(selector).data('type');
      installers = {};
      installerArray = [];
      selectedInstaller = {};
      cache = {};
      cacheCalendar = {};
      currentMonth = {start: null, end: null}
      standardInstallerObject = {jobs: {}, daysOfWeekDisabled: {}, time_off: {}, color:null}
      previousInstallerCount = 0;
      setup();
    }

function setup() {
       setupListeners();
       setupDatePickers();
       $('.installer-name').text('Select Installer');
       syncEventTypes();
       syncJobStatuses();
       fetchInstallers(setupCalendar);
     }

function fetchInstallers(callback) {
      $.ajax({
        url: serverpath + 'v1.0/users?role=installers',
        type: "GET",
        dataType: 'json'
      }).done(function(response) {
        loadInstallers(response);
        if(typeof callback === 'function') callback();
      })
      .fail(function(xhr) {
        handleError(xhr);
        $('#calendar-loading-indicator').fadeOut();
      })
      .always(function() { });
    }

    function loadInstallers(response) {
      for(var i in response) {

        var installer = response[i];
        var id = installer.id;
        //need to extend / copy object since the object would be stored by reference not by value
        var copiedObject = $.extend(true, {}, standardInstallerObject);
        var copiedObjectCalendar = $.extend(true, {}, standardInstallerObject);
        cache[id] = copiedObject;
        cacheCalendar[id] = copiedObjectCalendar;
        if(installers[id]) continue;
        installers[id] = installer;
        installerArray.push(installers[id]);
      }

      if(type == 'installer') {
        var installer = installers[$.User.id()];
        selectInstaller(installer);
        $('.installer-pick-list li[data-id="'+ $.User.id() +'"]').addClass('active');
      }
    }

      

+3


source to share


1 answer


Are you using an ajax call? Possibly mocking the long ajax call with setTimeout and see if you have the same error. So wrap the ajax call that is there with the setTimeout call and set it to 4000 or something. Here's a good example of what I'm talking about. using SetTimeout with Ajax calls

setTimeout(function(){checkData()}, 5000);
function checkData(){
    $.ajax({ 
        // 
    }); 
}

      

Since the download function is already running and the user is beating them up by choosing the installer, you can do something like this.

For the public



$.ajax({
    url: //something
    type: "GET",
    dataType: 'json'
    }).done(function(response) {
        loadInstallers(response);
        $.publish('Installer.set_installer_info');
        if(typeof callback === 'function') callback();
    })
});

      

For subscription

$.subscribe('Installer.set_installer_info', function() {
    $('body').on('click', '.installer-calendar-container .installer-pick-list .selectable', handleSelectInstaller);
});

      

+1


source







All Articles