PetTracker

PetTracker

13M Downloads

nil error when other addons modify the collected tooltip line

Pingumania opened this issue ยท 0 comments

commented

Which software were you running?

  • Addon version name: 10.1.1
  • Client used: Retail 10.1.7

Have you read the changelog?
Yes

Please describe the bug.
In PetTracker/addons/main/features/tooltips.lua is the function function Tooltips.OnUnit(tip) and executes a loop

for i = 1, tip:NumLines() do
  local line = _G[tip:GetName() .. 'TextLeft' .. i]
  if line:GetText():find('^' .. COLLECTED) then
    line:SetText(DIM_GREEN_FONT_COLOR:WrapTextInColorCode(owned))
    return
  end
end

If the return isn't reached (usually if other addons modify the collected tooltip line) and there is a line where GetText() returns nil you get the attempt to index a nil value error.

Please describe how to reproduce it.

  1. Add this snippet at the top to this function:
  tip:AddLine("TEST")
  for i = 1, tip:NumLines() do
    local line = _G[tip:GetName() .. 'TextLeft' .. i]
    if line:GetText():find('^' .. COLLECTED) then
      line:SetText("DEBUG")
    end
  end
  local text = nil
  _G[tip:GetName() .. 'TextLeft' .. 4]:SetText(text)
  1. Hover over a already collected battle pet in the wild
  2. Below error shows up

Quick fix
Change line 22 from

if line:GetText():find('^' .. COLLECTED) then

to

if (line:GetText() or ""):find('^' .. COLLECTED) then

Error Logs are Important!

1x PetTracker/addons/main/features/tooltips.lua:22: attempt to index a nil value
[string "@PetTracker/addons/main/features/tooltips.lua"]:22: in function <PetTracker/addons/main/features/tooltips.lua:14>
[string "=(tail call)"]: ?
[string "=[C]"]: in function `securecallfunction'
[string "@SharedXML/Tooltip/TooltipDataHandler.lua"]:162: in function <SharedXML/Tooltip/TooltipDataHandler.lua:157>
[string "@SharedXML/Tooltip/TooltipDataHandler.lua"]:182: in function <SharedXML/Tooltip/TooltipDataHandler.lua:178>
[string "@SharedXML/Tooltip/TooltipDataHandler.lua"]:218: in function <SharedXML/Tooltip/TooltipDataHandler.lua:208>
[string "=[C]"]: in function `SetAttribute'
[string "@SharedXML/Tooltip/TooltipDataHandler.lua"]:243: in function <SharedXML/Tooltip/TooltipDataHandler.lua:236>
[string "@SharedXML/Tooltip/TooltipDataHandler.lua"]:389: in function <SharedXML/Tooltip/TooltipDataHandler.lua:339>
[string "=[C]"]: in function `securecallfunction'
[string "@SharedXML/Tooltip/TooltipDataHandler.lua"]:336: in function `ProcessInfo'
[string "@FrameXML/GameTooltip.lua"]:1092: in function `SetWorldCursor'
[string "@FrameXML/UIParent.lua"]:1493: in function <FrameXML/UIParent.lua:1416>