From e2aef64a4d963a61e4dd595ee79120afa8572468 Mon Sep 17 00:00:00 2001 From: Chris Houseknecht Date: Wed, 29 Jan 2014 19:58:34 -0500 Subject: [PATCH] AC-995 fixed typo and added extra error handling in case we actually cannot parse inventory variables. If that does happen, we now alert the user and keep the application stable and running. --- awx/ui/static/js/helpers/inventory.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/awx/ui/static/js/helpers/inventory.js b/awx/ui/static/js/helpers/inventory.js index d88f5132e5..7c0b446015 100644 --- a/awx/ui/static/js/helpers/inventory.js +++ b/awx/ui/static/js/helpers/inventory.js @@ -137,12 +137,24 @@ angular.module('InventoryHelper', [ 'RestServices', 'Utilities', 'OrganizationLi if (fld == 'inventory_variables') { // Parse variables, converting to YAML. if ($.isEmptyObject(data.variables) || data.variables == "\{\}" || - data.variables == "null" || data.data_variables == "") { + data.variables == "null" || data.variables == "") { scope.inventory_variables = "---"; } else { - var json_obj = JSON.parse(data.variables); - scope.inventory_variables = jsyaml.safeDump(json_obj); + try { + var json_obj = JSON.parse(data.variables); + scope.inventory_variables = jsyaml.safeDump(json_obj); + } + catch(err) { + Alert('Variable Parse Error', 'Attempted to parse variables for inventory: ' + inventory_id + + '. Parse returned: ' + err); + if (console) { + console.log(err); + console.log('data:'); + console.log(data.variables); + } + scope.inventory_variables = '---'; + } } master.inventory_variables = scope.variables; }