Quantcast

Try to guard all instances of bad input for listing, so user can fix their own problems

James Whitehead II [10-15-10 - 08:59]
Try to guard all instances of bad input for listing, so user can fix their own problems
Filename
BindConfig.lua
Utils.lua
diff --git a/BindConfig.lua b/BindConfig.lua
index 2ddac99..f16a10a 100755
--- a/BindConfig.lua
+++ b/BindConfig.lua
@@ -283,6 +283,8 @@ compareFunctions = {
         local keyb = addon:GetBindingKey(b)
         if keya == keyb then
             return memoizeBindings[a] < memoizeBindings[b]
+        elseif not keya or not keyb then
+            return false
         else
             return keya < keyb
         end
diff --git a/Utils.lua b/Utils.lua
index e1964be..2038cce 100644
--- a/Utils.lua
+++ b/Utils.lua
@@ -87,6 +87,10 @@ local function convert(item, ...)
 end

 function addon:GetBindingIcon(binding)
+    if type(binding) ~= "table" or not binding.type then
+        return "Interface\\Icons\\INV_Misc_QuestionMark"
+    end
+
     local btype = binding.type
     if btype == "menu" then
         --return "Interface\\Icons\\Trade_Engineering"
@@ -100,10 +104,12 @@ function addon:GetBindingIcon(binding)
 end

 function addon:GetBindingKeyComboText(binding)
-    if type(binding) == "table" then
+    if type(binding) == "table" and binding.key then
         return strconcat(convert(strsplit("-", binding.key)))
     elseif type(binding) == "string" then
         return strconcat(convert(strsplit("-", binding)))
+    else
+        return L["Unknown"]
     end
 end

@@ -113,7 +119,7 @@ function addon:GetBindingActionText(btype, binding)
     elseif btype == "target" then
         return L["Target clicked unit"]
     elseif btype == "spell" then
-        return L["Cast %s"]:format(binding.spell)
+        return L["Cast %s"]:format(tostring(binding.spell))
     elseif btype == "macro" and type(binding) == "table" then
         return L["Run macro '%s'"]:format(tostring(binding.macrotext))
     elseif btype == "macro" then
@@ -124,6 +130,10 @@ function addon:GetBindingActionText(btype, binding)
 end

 function addon:GetBindingKey(binding)
+    if type(binding) ~= "table" or not binding.key then
+        return "UNKNOWN"
+    end
+
     local key = binding.key:match("[^%-]+$")
     return key
 end
@@ -141,6 +151,10 @@ local binMap = {
 }

 function addon:GetBinaryBindingKey(binding)
+    if type(binding) ~= "table" or not binding.key then
+        return "000000000"
+    end
+
     local ret = {"0", "0", "0", "0", "0", "0", "0", "0", "0"}
     local splits = {strsplit("-", binding.key)}
     for idx, modifier in ipairs(splits) do
@@ -193,6 +207,10 @@ function addon:GetCapturedKey(key)
 end

 function addon:GetBindingInfoText(binding)
+    if type(binding) ~= "table" or not binding.sets then
+        return L["This binding is invalid, please delete"]
+    end
+
     local sets = binding.sets
     if not sets then
         return ""
@@ -210,6 +228,10 @@ function addon:GetBindingInfoText(binding)
 end

 function addon:GetBindingPrefixSuffix(binding)
+    if type(binding) ~= "table" or not binding.key then
+        return "UNKNOWN", "UNKNOWN"
+    end
+
     local prefix, suffix = binding.key:match("^(.-)([^%-]+)$")
     if prefix:sub(-1, -1) == "-" then
         prefix = prefix:sub(1, -2)
@@ -232,6 +254,10 @@ end

 -- This function examines the current state of the game
 function addon:ShouldSetBinding(binding, global)
+    if type(binding) ~= table or not binding.key or not binding.sets then
+        return false
+    end
+
     local apply = false

     -- Check for global bindings first in isolation