Javascript 再现前端错误
因此,我作为实习生正在从事一个项目,该项目使用Bugsnag捕获他们的web应用程序中的错误。有一个错误,我试图修复,我无法复制。它只影响到我们所有使用该产品的客户中的两个人。我没有写这段代码,我只是试图修复其中的错误。错误是Javascript 再现前端错误,javascript,jquery,Javascript,Jquery,因此,我作为实习生正在从事一个项目,该项目使用Bugsnag捕获他们的web应用程序中的错误。有一个错误,我试图修复,我无法复制。它只影响到我们所有使用该产品的客户中的两个人。我没有写这段代码,我只是试图修复其中的错误。错误是TypeError·uncaughttypeerror:无法设置未定义的属性“selected”,它位于该函数的第二行 function selectInstaller(installer) { installers[installer.id].selected
TypeError·uncaughttypeerror:无法设置未定义的属性“selected”,它位于该函数的第二行
function selectInstaller(installer) {
installers[installer.id].selected = true;
selectedInstaller[installer.id] = installer;
}
假设有一个个人列表,用户可以选择一个人在日历上显示该特定个人的事件。选择用户后,将调用此函数
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();
}
}
如您所见,handleSelectInstaller函数随后调用selectInstaller函数,然后出现错误。正如我所说,这是一个罕见的错误发生,我看不到复制错误。我想那个特定的人的数据库可能有问题,但我的经理看了一下,他说看起来不错。他还尝试登录到用户的帐户,并试图以这种方式复制它,但它没有给他任何问题(因此他无法在他的计算机上复制它)。但是当用户登录到他们的计算机时,Bugsnag仍然在报告它。有没有关于如何重现此错误以便修复问题的想法?还是完全不受我的控制
编辑:以下是加载页面时的调用。最后一个功能将自动选择已登录的用户。然后,当用户(安装程序)选择或取消选择其名称时,将调用handleSelectInstaller函数。stacktrace显示我们进入handleSelectInstaller函数
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');
}
}
您正在使用ajax调用吗?也许可以使用setTimeout模拟一个长ajax调用,看看是否会出现相同的错误。因此,用setTimeout调用包装ajax调用,并将其设置为4000或类似的值。这里有一个很好的例子来说明我所说的。
由于load installers功能已经运行,用户首先选择一个安装程序,从而击败了他们,所以您可以这样做
面向公众
$.ajax({
url: //something
type: "GET",
dataType: 'json'
}).done(function(response) {
loadInstallers(response);
$.publish('Installer.set_installer_info');
if(typeof callback === 'function') callback();
})
});
订阅
$.subscribe('Installer.set_installer_info', function() {
$('body').on('click', '.installer-calendar-container .installer-pick-list .selectable', handleSelectInstaller);
});
变量安装程序是在什么地方定义的吗?因为看起来数组安装程序没有installer.idies的密钥,如果您想查看,我添加了更多代码。您可以联系用户吗?也许可以找出他们使用的浏览器,并尝试在特定的系统上复制它?这是个好主意。我会和老板谈谈。我会调查酒吧/酒吧或承诺。我将编辑我的帖子,向您展示如何完成。ajax请求有一个函数,可以在.done中加载安装程序。如果用户在加载安装程序之前单击它,则会发生错误。我从没听说过酒吧/酒吧,但我查了一下,这正是我想要的。
$.subscribe('Installer.set_installer_info', function() {
$('body').on('click', '.installer-calendar-container .installer-pick-list .selectable', handleSelectInstaller);
});