From f1a1b851ee55ef50e7d5ed2bc86c37f151984131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 17 Nov 2016 17:15:28 +0100 Subject: [PATCH] Better resilience against exceptions in view models in callViewModels --- src/octoprint/static/js/app/helpers.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/octoprint/static/js/app/helpers.js b/src/octoprint/static/js/app/helpers.js index dae6d8fd..81c3b9c9 100644 --- a/src/octoprint/static/js/app/helpers.js +++ b/src/octoprint/static/js/app/helpers.js @@ -832,17 +832,21 @@ function callViewModelsIf(allViewModels, method, condition, callback) { _.each(allViewModels, function(viewModel) { if (viewModel.hasOwnProperty(method) && condition(viewModel, method)) { - if (callback == undefined) { - if (parameters != undefined) { - // call the method with the provided parameters - viewModel[method].apply(viewModel, parameters); + try { + if (callback == undefined) { + if (parameters != undefined) { + // call the method with the provided parameters + viewModel[method].apply(viewModel, parameters); + } else { + // call the method without parameters + viewModel[method](); + } } else { - // call the method without parameters - viewModel[method](); + // provide the method to the callback + callback(viewModel[method], viewModel); } - } else { - // provide the method to the callback - callback(viewModel[method], viewModel); + } catch (exc) { + log.error("Error calling", method, "on view model", viewModel.constructor.name, ":", (exc.stack || exc)); } } });