From 74a1a856ac5ac6b1fc8e553263097dcc40b3f0e3 Mon Sep 17 00:00:00 2001 From: NoM0Re Date: Tue, 7 Jan 2025 15:03:14 +0100 Subject: [PATCH] from retail --- WeakAuras/Animations.lua | 17 ++++-- WeakAuras/AuraEnvironment.lua | 6 +- WeakAuras/Conditions.lua | 10 ++-- WeakAuras/GenericTrigger.lua | 60 +++++++++---------- WeakAuras/RegionTypes/DynamicGroup.lua | 13 +++-- WeakAuras/RegionTypes/RegionPrototype.lua | 6 +- WeakAuras/RegionTypes/Text.lua | 2 +- WeakAuras/SubRegionTypes/SubText.lua | 2 +- WeakAuras/WeakAuras.lua | 71 +++++++++++++++++------ 9 files changed, 115 insertions(+), 72 deletions(-) diff --git a/WeakAuras/Animations.lua b/WeakAuras/Animations.lua index 1a98194..59a10a2 100644 --- a/WeakAuras/Animations.lua +++ b/WeakAuras/Animations.lua @@ -1,5 +1,6 @@ if not WeakAuras.IsLibsOK() then return end local AddonName, Private = ... +local L = WeakAuras.L -- Animations local animations = {} @@ -14,7 +15,6 @@ local updatingAnimations; local last_update = GetTime(); local function UpdateAnimations() Private.StartProfileSystem("animations"); - local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or geterrorhandler() for groupUid, groupRegion in pairs(pending_controls) do pending_controls[groupUid] = nil; groupRegion:DoPositionChildren(); @@ -72,6 +72,7 @@ local function UpdateAnimations() progress = anim.easeFunc(progress, anim.easeStrength or 3) Private.ActivateAuraEnvironmentForRegion(anim.region) if(anim.translateFunc) then + local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Slide Animation"]) if (anim.region.SetOffsetAnim) then local ok, x, y = pcall(anim.translateFunc, progress, 0, 0, anim.dX, anim.dY); if not ok then @@ -90,6 +91,7 @@ local function UpdateAnimations() end end if(anim.alphaFunc) then + local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Fade Animation"]) local ok, alpha = pcall(anim.alphaFunc, progress, anim.startAlpha, anim.dAlpha); if not ok then errorHandler(alpha) @@ -102,6 +104,7 @@ local function UpdateAnimations() end end if(anim.scaleFunc) then + local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Zoom Animation"]) local ok, scaleX, scaleY = pcall(anim.scaleFunc, progress, 1, 1, anim.scaleX, anim.scaleY); if not ok then errorHandler(scaleX) @@ -115,6 +118,7 @@ local function UpdateAnimations() end end if(anim.rotateFunc and anim.region.Rotate) then + local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Rotate Animation"]) local ok, rotate = pcall(anim.rotateFunc, progress, anim.startRotation, anim.rotate); if not ok then errorHandler(rotate) @@ -123,6 +127,7 @@ local function UpdateAnimations() end end if(anim.colorFunc and anim.region.ColorAnim) then + local errorHandler = WeakAuras.IsOptionsOpen() and noopErrorHandler or Private.GetErrorHandlerUid(anim.auraUID, L["Color Animation"]) local startR, startG, startB, startA = anim.region:GetColor(); startR, startG, startB, startA = startR or 1, startG or 1, startB or 1, startA or 1; local ok, r, g, b, a = pcall(anim.colorFunc, progress, startR, startG, startB, startA, anim.colorR, anim.colorG, anim.colorB, anim.colorA); @@ -240,7 +245,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished anim.translateFunc = anim_function_strings[anim.translateType] end if (anim.translateFunc) then - translateFunc = WeakAuras.LoadFunction("return " .. anim.translateFunc, auraDisplayName, "translate animation"); + translateFunc = WeakAuras.LoadFunction("return " .. anim.translateFunc); else if (region.SetOffsetAnim) then region:SetOffsetAnim(0, 0); @@ -261,7 +266,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished anim.alphaFunc = anim_function_strings[anim.alphaType] end if (anim.alphaFunc) then - alphaFunc = WeakAuras.LoadFunction("return " .. anim.alphaFunc, auraDisplayName, "alpha animation"); + alphaFunc = WeakAuras.LoadFunction("return " .. anim.alphaFunc); else if (region.SetAnimAlpha) then region:SetAnimAlpha(nil); @@ -282,7 +287,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished anim.scaleFunc = anim_function_strings[anim.scaleType] end if (anim.scaleFunc) then - scaleFunc = WeakAuras.LoadFunction("return " .. anim.scaleFunc, auraDisplayName, "scale animation"); + scaleFunc = WeakAuras.LoadFunction("return " .. anim.scaleFunc); else region:Scale(1, 1); end @@ -295,7 +300,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished anim.rotateFunc = anim_function_strings[anim.rotateType] end if (anim.rotateFunc) then - rotateFunc = WeakAuras.LoadFunction("return " .. anim.rotateFunc, auraDisplayName, "rotate animation"); + rotateFunc = WeakAuras.LoadFunction("return " .. anim.rotateFunc); else region:Rotate(startRotation); end @@ -308,7 +313,7 @@ function Private.Animate(namespace, uid, type, anim, region, inverse, onFinished anim.colorFunc = anim_function_strings[anim.colorType] end if (anim.colorFunc) then - colorFunc = WeakAuras.LoadFunction("return " .. anim.colorFunc, auraDisplayName, "color animation"); + colorFunc = WeakAuras.LoadFunction("return " .. anim.colorFunc); else region:ColorAnim(nil); end diff --git a/WeakAuras/AuraEnvironment.lua b/WeakAuras/AuraEnvironment.lua index 285fcb3..ed29fdc 100644 --- a/WeakAuras/AuraEnvironment.lua +++ b/WeakAuras/AuraEnvironment.lua @@ -269,7 +269,7 @@ function Private.ActivateAuraEnvironment(id, cloneId, state, states, onlyConfig) if(actions and actions.do_custom and actions.custom) then local func = Private.customActionsFunctions[id]["init"] if func then - xpcall(func, geterrorhandler()) + xpcall(func, Private.GetErrorHandlerId(id, "init")) end end end @@ -425,11 +425,11 @@ function env_getglobal(k) end local function_cache = {} -function WeakAuras.LoadFunction(string, id, inTrigger) +function WeakAuras.LoadFunction(string) if function_cache[string] then return function_cache[string] else - local loadedFunction, errorString = loadstring(string, "Error in: " .. (id or "Unknown") .. (inTrigger and ("':'".. inTrigger) or "")) + local loadedFunction, errorString = loadstring(string) if errorString then print(errorString) else diff --git a/WeakAuras/Conditions.lua b/WeakAuras/Conditions.lua index dea2034..73fd986 100644 --- a/WeakAuras/Conditions.lua +++ b/WeakAuras/Conditions.lua @@ -151,7 +151,7 @@ end function WeakAuras.CallCustomConditionTest(uid, testFunctionNumber, ...) local ok, result = pcall(WeakAuras.conditionHelpers[uid].customTestFunctions[testFunctionNumber], ...) if not ok then - geterrorhandler()(result) + Private.GetErrorHandlerUid(uid, L["Condition Custom Text"]) elseif (ok) then return result end @@ -223,7 +223,7 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta end elseif (cType == "customcheck") then if value then - local customCheck = WeakAuras.LoadFunction("return " .. value, Private.UIDtoID(uid), "conditions custom check") + local customCheck = WeakAuras.LoadFunction("return " .. value) if customCheck then WeakAuras.conditionHelpers[uid] = WeakAuras.conditionHelpers[uid] or {} WeakAuras.conditionHelpers[uid].customTestFunctions = WeakAuras.conditionHelpers[uid].customTestFunctions or {} @@ -295,7 +295,7 @@ local function CreateTestForCondition(uid, input, allConditionsTemplate, usedSta fn = fn:format(input.op_range, input.range, op, value) end if fn then - local customCheck = WeakAuras.LoadFunction(fn, Private.UIDtoID(uid), "conditions range check") + local customCheck = WeakAuras.LoadFunction(fn) if customCheck then WeakAuras.conditionHelpers[uid] = WeakAuras.conditionHelpers[uid] or {} WeakAuras.conditionHelpers[uid].customTestFunctions = WeakAuras.conditionHelpers[uid].customTestFunctions or {} @@ -517,7 +517,7 @@ function Private.LoadConditionPropertyFunctions(data) else prefix, suffix = "return function()", "\nend"; end - local customFunc = WeakAuras.LoadFunction(prefix .. custom .. suffix, id, "condition"); + local customFunc = WeakAuras.LoadFunction(prefix .. custom .. suffix); if (customFunc) then WeakAuras.customConditionsFunctions[id][conditionNumber] = WeakAuras.customConditionsFunctions[id][conditionNumber] or {}; WeakAuras.customConditionsFunctions[id][conditionNumber].changes = WeakAuras.customConditionsFunctions[id][conditionNumber].changes or {}; @@ -697,7 +697,7 @@ function Private.LoadConditionFunction(data) CancelTimers(data.uid) local checkConditionsFuncStr = ConstructConditionFunction(data); - local checkCondtionsFunc = checkConditionsFuncStr and WeakAuras.LoadFunction(checkConditionsFuncStr, data.id, "condition checks"); + local checkCondtionsFunc = checkConditionsFuncStr and WeakAuras.LoadFunction(checkConditionsFuncStr); checkConditions[data.uid] = checkCondtionsFunc; end diff --git a/WeakAuras/GenericTrigger.lua b/WeakAuras/GenericTrigger.lua index 6768143..482cfaa 100644 --- a/WeakAuras/GenericTrigger.lua +++ b/WeakAuras/GenericTrigger.lua @@ -457,7 +457,7 @@ function Private.EndEvent(id, triggernum, force, state) end end -local function RunOverlayFuncs(event, state) +local function RunOverlayFuncs(event, state, id) state.additionalProgress = state.additionalProgress or {}; local changed = false; for i, overlayFunc in ipairs(event.overlayFuncs) do @@ -465,7 +465,7 @@ local function RunOverlayFuncs(event, state) local additionalProgress = state.additionalProgress[i]; local ok, a, b, c = pcall(overlayFunc, event.trigger, state); if (not ok) then - geterrorhandler()(a) + Private.GetErrorHandlerId(id, L["Overlay %s"]:format(i)) additionalProgress.min = nil; additionalProgress.max = nil; additionalProgress.direction = nil; @@ -522,7 +522,7 @@ local function callFunctionForActivateEvent(func, trigger, fallback, errorHandle end end -function Private.ActivateEvent(id, triggernum, data, state, errorHandler) +function Private.ActivateEvent(id, triggernum, data, state) local changed = state.changed or false; if (state.show ~= true) then state.show = true; @@ -553,7 +553,7 @@ function Private.ActivateEvent(id, triggernum, data, state, errorHandler) elseif (data.durationFunc) then local ok, arg1, arg2, arg3, inverse = pcall(data.durationFunc, data.trigger); if not ok then - errorHandler(arg1); + Private.GetErrorHandlerId(id, L["Duration Function"]) arg1 = 0; arg2 = 0; else @@ -619,10 +619,10 @@ function Private.ActivateEvent(id, triggernum, data, state, errorHandler) end end - local name = callFunctionForActivateEvent(data.nameFunc, data.trigger, state.name, errorHandler) - local icon = callFunctionForActivateEvent(data.iconFunc, data.trigger, state.icon, errorHandler) - local texture = callFunctionForActivateEvent(data.textureFunc, data.trigger, state.texture, errorHandler) - local stacks = callFunctionForActivateEvent(data.stacksFunc, data.trigger, state.stacks, errorHandler) + local name = callFunctionForActivateEvent(data.nameFunc, data.trigger, state.name, Private.GetErrorHandlerId(id, L["Name Function"])) + local icon = callFunctionForActivateEvent(data.iconFunc, data.trigger, state.icon, Private.GetErrorHandlerId(id, L["Icon Function"])) + local texture = callFunctionForActivateEvent(data.textureFunc, data.trigger, state.texture, Private.GetErrorHandlerId(id, L["Texture Function"])) + local stacks = callFunctionForActivateEvent(data.stacksFunc, data.trigger, state.stacks, Private.GetErrorHandlerId(id, L["Stacks Function"])) if (state.name ~= name) then state.name = name; @@ -642,7 +642,7 @@ function Private.ActivateEvent(id, triggernum, data, state, errorHandler) end if (data.overlayFuncs) then - RunOverlayFuncs(data, state); + RunOverlayFuncs(data, state, id); else state.additionalProgress = nil; end @@ -658,7 +658,7 @@ end local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2, ...) local optionsEvent = event == "OPTIONS"; - local errorHandler = (optionsEvent and data.ignoreOptionsEventErrors) and ignoreErrorHandler or geterrorhandler() + local errorHandler = (optionsEvent and data.ignoreOptionsEventErrors) and ignoreErrorHandler or Private.GetErrorHandlerId(id, L["Trigger %s"]:format(triggernum)) local updateTriggerState = false; local unitForUnitTrigger @@ -675,7 +675,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 end for key, state in pairs(allStates) do if (type(state) ~= "table") then - errorHandler(string.format(L["Error in aura '%s' in %s. trigger. All States table contains a non table at key: '%s'."], id, triggernum, key)) + errorHandler(string.format(L["All States table contains a non table at key: '%s'."], key)) wipe(allStates) return end @@ -687,7 +687,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 elseif (ok and returnValue) or optionsEvent then for id, state in pairs(allStates) do if (state.changed) then - if (Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then + if (Private.ActivateEvent(id, triggernum, data, state)) then updateTriggerState = true; end end @@ -721,7 +721,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 if not ok then errorHandler(returnValue) elseif (ok and returnValue) or optionsEvent then - if(Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then + if(Private.ActivateEvent(id, triggernum, data, state)) then updateTriggerState = true; end else @@ -735,7 +735,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 if not ok then errorHandler(returnValue) elseif (ok and returnValue) or optionsEvent then - if(Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then + if(Private.ActivateEvent(id, triggernum, data, state)) then updateTriggerState = true; end else @@ -748,7 +748,7 @@ local function RunTriggerFunc(allStates, data, id, triggernum, event, arg1, arg2 elseif (ok and returnValue) or optionsEvent then allStates[""] = allStates[""] or {}; local state = allStates[""]; - if(Private.ActivateEvent(id, triggernum, data, state, errorHandler)) then + if(Private.ActivateEvent(id, triggernum, data, state)) then updateTriggerState = true; end else @@ -1391,7 +1391,7 @@ function GenericTrigger.Add(data, region) triggerFuncStr = ConstructFunction(prototype, trigger); statesParameter = prototype.statesParameter; - triggerFunc = WeakAuras.LoadFunction(triggerFuncStr, id); + triggerFunc = WeakAuras.LoadFunction(triggerFuncStr); durationFunc = prototype.durationFunc; nameFunc = prototype.nameFunc; @@ -1455,7 +1455,7 @@ function GenericTrigger.Add(data, region) end end else -- CUSTOM - triggerFunc = WeakAuras.LoadFunction("return "..(trigger.custom or ""), id); + triggerFunc = WeakAuras.LoadFunction("return "..(trigger.custom or "")); if (trigger.custom_type == "stateupdate") then tsuConditionVariables = WeakAuras.LoadFunction("return function() return \n" .. (trigger.customVariables or "") .. "\n end"); if not tsuConditionVariables then @@ -1464,35 +1464,35 @@ function GenericTrigger.Add(data, region) end if(trigger.custom_type == "status" or trigger.custom_type == "event" and trigger.custom_hide == "custom") then - untriggerFunc = WeakAuras.LoadFunction("return "..(untrigger.custom or ""), id); + untriggerFunc = WeakAuras.LoadFunction("return "..(untrigger.custom or "")); if (not untriggerFunc) then untriggerFunc = trueFunction; end end if(trigger.custom_type ~= "stateupdate" and trigger.customDuration and trigger.customDuration ~= "") then - durationFunc = WeakAuras.LoadFunction("return "..trigger.customDuration, id); + durationFunc = WeakAuras.LoadFunction("return "..trigger.customDuration); end if(trigger.custom_type ~= "stateupdate") then overlayFuncs = {}; for i = 1, 7 do local property = "customOverlay" .. i; if (trigger[property] and trigger[property] ~= "") then - overlayFuncs[i] = WeakAuras.LoadFunction("return ".. trigger[property], id); + overlayFuncs[i] = WeakAuras.LoadFunction("return ".. trigger[property]); end end end if(trigger.custom_type ~= "stateupdate" and trigger.customName and trigger.customName ~= "") then - nameFunc = WeakAuras.LoadFunction("return "..trigger.customName, id); + nameFunc = WeakAuras.LoadFunction("return "..trigger.customName); end if(trigger.custom_type ~= "stateupdate" and trigger.customIcon and trigger.customIcon ~= "") then - iconFunc = WeakAuras.LoadFunction("return "..trigger.customIcon, id); + iconFunc = WeakAuras.LoadFunction("return "..trigger.customIcon); end if(trigger.custom_type ~= "stateupdate" and trigger.customTexture and trigger.customTexture ~= "") then - textureFunc = WeakAuras.LoadFunction("return "..trigger.customTexture, id); + textureFunc = WeakAuras.LoadFunction("return "..trigger.customTexture); end if(trigger.custom_type ~= "stateupdate" and trigger.customStacks and trigger.customStacks ~= "") then - stacksFunc = WeakAuras.LoadFunction("return "..trigger.customStacks, id); + stacksFunc = WeakAuras.LoadFunction("return "..trigger.customStacks); end if((trigger.custom_type == "status" or trigger.custom_type == "stateupdate") and trigger.check == "update") then @@ -4098,7 +4098,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) if (event.nameFunc) then local ok, name = pcall(event.nameFunc, firstTrigger); if not ok then - geterrorhandler()(name) + Private.GetErrorHandlerUid(data.uid, L["Name Function (fallback state)"]) state.name = nil else state.name = name or nil @@ -4107,7 +4107,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) if (event.iconFunc) then local ok, icon = pcall(event.iconFunc, firstTrigger); if not ok then - geterrorhandler()(icon) + Private.GetErrorHandlerUid(data.uid, L["Icon Function (fallback state)"]) state.icon = nil else state.icon = icon or nil @@ -4117,7 +4117,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) if (event.textureFunc ) then local ok, texture = pcall(event.textureFunc, firstTrigger); if not ok then - geterrorhandler()(texture) + Private.GetErrorHandlerUid(data.uid, L["Texture Function (fallback state)"]) state.texture = nil else state.texture = texture or nil @@ -4127,7 +4127,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) if (event.stacksFunc) then local ok, stacks = pcall(event.stacksFunc, firstTrigger); if not ok then - geterrorhandler()(stacks) + Private.GetErrorHandlerUid(data.uid, L["Stacks Function (fallback state)"]) state.stacks = nil else state.stacks = stacks or nil @@ -4137,7 +4137,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) if (event.durationFunc) then local ok, arg1, arg2, arg3, inverse = pcall(event.durationFunc, firstTrigger); if not ok then - geterrorhandler()(arg1) + Private.GetErrorHandlerUid(data.uid, L["Duration Function (fallback state)"]) state.progressType = "timed"; state.duration = 0; state.expirationTime = math.huge; @@ -4180,7 +4180,7 @@ function GenericTrigger.CreateFallbackState(data, triggernum, state) state.total = nil; end if (event.overlayFuncs) then - RunOverlayFuncs(event, state); + RunOverlayFuncs(event, state, data.id); end Private.ActivateAuraEnvironment(nil); end diff --git a/WeakAuras/RegionTypes/DynamicGroup.lua b/WeakAuras/RegionTypes/DynamicGroup.lua index e9877cc..3f6c294 100644 --- a/WeakAuras/RegionTypes/DynamicGroup.lua +++ b/WeakAuras/RegionTypes/DynamicGroup.lua @@ -2,6 +2,7 @@ if not WeakAuras.IsLibsOK() then return end local AddonName, Private = ... local WeakAuras = WeakAuras +local L = WeakAuras.L local SharedMedia = LibStub("LibSharedMedia-3.0") local default = { @@ -317,13 +318,13 @@ local sorters = { end, custom = function(data) local sortStr = data.customSort or "" - local sortFunc = WeakAuras.LoadFunction("return " .. sortStr, data.id, "custom sort") or noop + local sortFunc = WeakAuras.LoadFunction("return " .. sortStr) or noop return function(a, b) Private.ActivateAuraEnvironment(data.id) local ok, result = pcall(sortFunc, a, b) Private.ActivateAuraEnvironment() if not ok then - geterrorhandler()(result) + Private.GetErrorHandlerId(data.id, L["Custom Sort"]) else return result end @@ -398,12 +399,12 @@ local anchorers = { end, ["CUSTOM"] = function(data) local anchorStr = data.customAnchorPerUnit or "" - local anchorFunc = WeakAuras.LoadFunction("return " .. anchorStr, data.id, "custom frame anchor") or noop + local anchorFunc = WeakAuras.LoadFunction("return " .. anchorStr) or noop return function(frames, activeRegions) Private.ActivateAuraEnvironment(data.id) local ok, ret = pcall(anchorFunc, frames, activeRegions) if not ok then - geterrorhandler()(ret) + Private.GetErrorHandlerUid(data.uid, L["Custom Anchor"]) end Private.ActivateAuraEnvironment() end @@ -763,13 +764,13 @@ local growers = { end, CUSTOM = function(data) local growStr = data.customGrow or "" - local growFunc = WeakAuras.LoadFunction("return " .. growStr, data.id, "custom grow") or noop + local growFunc = WeakAuras.LoadFunction("return " .. growStr) or noop return function(newPositions, activeRegions) Private.ActivateAuraEnvironment(data.id) local ok, ret = pcall(growFunc, newPositions, activeRegions) Private.ActivateAuraEnvironment() if not ok then - geterrorhandler()(ret) + Private.GetErrorHandlerId(data.id, L["Custom Sort"]) wipe(newPositions) end end diff --git a/WeakAuras/RegionTypes/RegionPrototype.lua b/WeakAuras/RegionTypes/RegionPrototype.lua index 8929f52..e340535 100644 --- a/WeakAuras/RegionTypes/RegionPrototype.lua +++ b/WeakAuras/RegionTypes/RegionPrototype.lua @@ -253,7 +253,7 @@ end local function RunCode(self, func) if func and not WeakAuras.IsOptionsOpen() then Private.ActivateAuraEnvironment(self.id, self.cloneId, self.state, self.states); - xpcall(func, geterrorhandler()); + xpcall(func, Private.GetErrorHandlerId(self.id, L["Custom Condition Code"])); Private.ActivateAuraEnvironment(nil); end end @@ -276,7 +276,7 @@ local function UpdatePosition(self) local ok, ret = pcall(self.SetPoint, self, self.anchorPoint, self.relativeTo, self.relativePoint, xOffset, yOffset); if not ok then - geterrorhandler()(ret) + Private.GetErrorHandlerId(self.id, L["Update Position"]) end end @@ -541,7 +541,7 @@ function WeakAuras.regionPrototype.modify(parent, region, data) region:SetOffsetAnim(0, 0); if data.anchorFrameType == "CUSTOM" and data.customAnchor then - region.customAnchorFunc = WeakAuras.LoadFunction("return " .. data.customAnchor, data.id, "custom anchor") + region.customAnchorFunc = WeakAuras.LoadFunction("return " .. data.customAnchor) else region.customAnchorFunc = nil end diff --git a/WeakAuras/RegionTypes/Text.lua b/WeakAuras/RegionTypes/Text.lua index baf2b94..43f6413 100644 --- a/WeakAuras/RegionTypes/Text.lua +++ b/WeakAuras/RegionTypes/Text.lua @@ -195,7 +195,7 @@ local function modify(parent, region, data) local customTextFunc = nil if(Private.ContainsCustomPlaceHolder(data.displayText) and data.customText) then - customTextFunc = WeakAuras.LoadFunction("return "..data.customText, region.id, "custom text") + customTextFunc = WeakAuras.LoadFunction("return "..data.customText) end local Update diff --git a/WeakAuras/SubRegionTypes/SubText.lua b/WeakAuras/SubRegionTypes/SubText.lua index c7842df..da4553e 100644 --- a/WeakAuras/SubRegionTypes/SubText.lua +++ b/WeakAuras/SubRegionTypes/SubText.lua @@ -192,7 +192,7 @@ local function modify(parent, region, parentData, data, first) end if containsCustomText and parentData.customText and parentData.customText ~= "" then - parent.customTextFunc = WeakAuras.LoadFunction("return "..parentData.customText, parentData.id, "custom text") + parent.customTextFunc = WeakAuras.LoadFunction("return "..parentData.customText) else parent.customTextFunc = nil end diff --git a/WeakAuras/WeakAuras.lua b/WeakAuras/WeakAuras.lua index a592435..49c1452 100644 --- a/WeakAuras/WeakAuras.lua +++ b/WeakAuras/WeakAuras.lua @@ -63,6 +63,46 @@ function WeakAuras.InternalVersion() return internalVersion; end +do + local currentErrorHandlerId + local currentErrorHandlerUid + local currentErrorHandlerContext + local function waErrorHandler(errorMessage) + local prefix = "" + local data + if currentErrorHandlerId then + data = WeakAuras.GetData(currentErrorHandlerId) + elseif currentErrorHandlerUid then + data = Private.GetDataByUID(currentErrorHandlerUid) + end + if data then + Private.AuraWarnings.UpdateWarning(data.uid, "LuaError", "error", + L["This aura has caused a Lua error."] .. "\n" .. L["Install the addons BugSack and BugGrabber for detailed error logs."], true) + prefix = L["Lua error in aura '%s': %s"]:format(data.id, currentErrorHandlerContext or L["unknown location"]) .. "\n" + else + prefix = L["Lua error"] .. "\n" + end + prefix = prefix .. L["WeakAuras Version: %s"]:format(WeakAuras.versionString) .. "\n" + local version = data and (data.semver or data.version) + if version then + prefix = prefix .. L["Aura Version: %s"]:format(version) .. "\n" + end + geterrorhandler()(prefix .. errorMessage) + end + function Private.GetErrorHandlerId(id, context) + currentErrorHandlerUid = nil + currentErrorHandlerId = id + currentErrorHandlerContext = context + return waErrorHandler + end + function Private.GetErrorHandlerUid(uid, context) + currentErrorHandlerUid = uid + currentErrorHandlerId = nil + currentErrorHandlerContext = context + return waErrorHandler + end +end + function Private.LoadOptions(msg) if not(IsAddOnLoaded("WeakAurasOptions")) then if not WeakAuras.IsLoginFinished() then @@ -796,30 +836,30 @@ local function LoadCustomActionFunctions(data) if (data.actions) then if (data.actions.init and data.actions.init.do_custom and data.actions.init.custom) then - local func = WeakAuras.LoadFunction("return function() "..(data.actions.init.custom).."\n end", id, "initialization"); + local func = WeakAuras.LoadFunction("return function() "..(data.actions.init.custom).."\n end"); Private.customActionsFunctions[id]["init"] = func; end if (data.actions.start) then if (data.actions.start.do_custom and data.actions.start.custom) then - local func = WeakAuras.LoadFunction("return function() "..(data.actions.start.custom).."\n end", id, "show action"); + local func = WeakAuras.LoadFunction("return function() "..(data.actions.start.custom).."\n end"); Private.customActionsFunctions[id]["start"] = func; end if (data.actions.start.do_message and data.actions.start.message_custom) then - local func = WeakAuras.LoadFunction("return "..(data.actions.start.message_custom), id, "show message"); + local func = WeakAuras.LoadFunction("return "..(data.actions.start.message_custom)); Private.customActionsFunctions[id]["start_message"] = func; end end if (data.actions.finish) then if (data.actions.finish.do_custom and data.actions.finish.custom) then - local func = WeakAuras.LoadFunction("return function() "..(data.actions.finish.custom).."\n end", id, "hide action"); + local func = WeakAuras.LoadFunction("return function() "..(data.actions.finish.custom).."\n end"); Private.customActionsFunctions[id]["finish"] = func; end if (data.actions.finish.do_message and data.actions.finish.message_custom) then - local func = WeakAuras.LoadFunction("return "..(data.actions.finish.message_custom), id, "hide message"); + local func = WeakAuras.LoadFunction("return "..(data.actions.finish.message_custom)); Private.customActionsFunctions[id]["finish_message"] = func; end end @@ -2605,11 +2645,11 @@ local function pAdd(data, simpleChange) loadEvents["SCAN_ALL"][id] = true local loadForOptionsFuncStr = ConstructFunction(load_prototype, data.load, true); - local loadFunc = WeakAuras.LoadFunction(loadFuncStr, id, "load"); - local loadForOptionsFunc = WeakAuras.LoadFunction(loadForOptionsFuncStr, id, "options load"); + local loadFunc = WeakAuras.LoadFunction(loadFuncStr); + local loadForOptionsFunc = WeakAuras.LoadFunction(loadForOptionsFuncStr); local triggerLogicFunc; if data.triggers.disjunctive == "custom" then - triggerLogicFunc = WeakAuras.LoadFunction("return "..(data.triggers.customTriggerLogic or ""), id, "trigger combination"); + triggerLogicFunc = WeakAuras.LoadFunction("return "..(data.triggers.customTriggerLogic or "")); end LoadCustomActionFunctions(data); @@ -2668,7 +2708,7 @@ function WeakAuras.Add(data, takeSnapshot, simpleChange) end local ok, ret = pcall(WeakAuras.PreAdd, data) if not ok then - geterrorhandler()(ret) + Private.GetErrorHandlerUid(data.uid, "PreAdd") elseif ok then pAdd(data, simpleChange) end @@ -3177,7 +3217,7 @@ function Private.PerformActions(data, when, region) local func = Private.customActionsFunctions[data.id][when] if func then Private.ActivateAuraEnvironment(region.id, region.cloneId, region.state, region.states); - xpcall(func, geterrorhandler()); + xpcall(func, Private.GetErrorHandlerId(data.id, L["Custom Action"])); Private.ActivateAuraEnvironment(nil); end end @@ -3854,7 +3894,7 @@ local function evaluateTriggerStateTriggers(id) if (triggerState[id].disjunctive == "custom" and triggerState[id].triggerLogicFunc) then local ok, returnValue = pcall(triggerState[id].triggerLogicFunc, triggerState[id].triggers); if not ok then - geterrorhandler()(returnValue) + Private.GetErrorHandlerId(id, L["Custom Trigger Combination"]) result = false else result = returnValue @@ -4073,7 +4113,7 @@ function Private.RunCustomTextFunc(region, customFunc) local custom = {pcall(customFunc, expirationTime or math.huge, duration or 0, progress, dur, name, icon, stacks)} if not custom[1] then - geterrorhandler()(custom[2]) + Private.GetErrorHandlerId(region.id, L["Custom Text Function"]) else table.remove(custom, 1) end @@ -4882,7 +4922,7 @@ local function GetAnchorFrame(data, region, parent) Private.StartProfileSystem("custom region anchor") Private.StartProfileAura(region.id) Private.ActivateAuraEnvironment(region.id, region.cloneId, region.state) - local ok, frame = xpcall(region.customAnchorFunc, geterrorhandler()) + local ok, frame = xpcall(region.customAnchorFunc, Private.GetErrorHandlerId(region.id, L["Custom Anchor"])) Private.ActivateAuraEnvironment() Private.StopProfileSystem("custom region anchor") Private.StopProfileAura(region.id) @@ -4915,12 +4955,9 @@ function Private.AnchorFrame(data, region, parent, force) if not anchorParent then return end if (data.anchorFrameParent or data.anchorFrameParent == nil or data.anchorFrameType == "SCREEN" or data.anchorFrameType == "MOUSE") then - local errorhandler = function(text) - geterrorhandler()(L["'ERROR: Anchoring %s': \n"]:format(data.id) .. text) - end local ok, ret = pcall(region.SetParent, region, anchorParent); if not ok then - errorhandler(ret) + Private.GetErrorHandlerId(data.id, L["Anchoring"]) end else region:SetParent(parent or WeakAurasFrame);