Quantcast Event LUA_WARNING payload 0 and NULL - WoWInterface
Thread Tools Display Modes
06-02-20, 06:35 PM   #1
AreGee
A Defias Bandit
Join Date: Jun 2020
Posts: 3
Event LUA_WARNING payload 0 and NULL

I did register for the event LUA_WARNING in case it would catch some of the silent errors that I have been getting, and indeed I do receive these events. The problem is that the payload is 0 (null) every single time and I can't for the world understand what is going wrong. I have no problem getting the payload from any of the other events that I am handling.

Here is the function that is receiving and handling the events:

Code:
local function AST_Event_LUAWarning(self, event, ...)
 local warnType, warningText = ...
 print("Warning: LUA_WARNING, type: " .. tostring(warnType) .. ", text: " .. warningText)
end
The function is handled by a generic event handler that I made. It is working for all other events, but I include it in case someone wants to investigate:

Code:
local function AST_EventAlreadyRegistered(newEventName)
 assert(type(newEventName) == "string", "Error: function AST_EventAlredyRegistered(newEventName)\n   - Input type is not a 'string'.")

--[[
 if not (type(newEventName) == "string") then
  print("Error: function AST_EventAlredyRegistered(newEventName)")
  print("   - Input type is not a 'string'.")
  return false
 end
--]] 
 for i, item in ipairs(_V.Events) do
  local existingEventName, func = item["eventName"], item["func"]
  if newEventName == existingEventName then
   return true
  end
 end
 return false
end

local function AST_RegisterEvent(frame, eventName, func)
 if AST_EventAlreadyRegistered(eventName) then
  print("Warning: function AST_RegisterEvent(eventName, func)")
  print("   - Silently dropping double registering of event '" .. eventName .. "'.")
  return
 end
 local item = {frame = frame, eventName = eventName, func = func}
 table.insert(_V.Events, item)
 frame:RegisterEvent(eventName)
end

local function AST_MainEventHandler(self, event, ...)
 local eventWasHandled = false
 
 for i, item in ipairs(_V.Events) do
  if item.eventName == event then
   eventWasHandled = true

   local t = type(item.func)

   if t == "function" then
    item.func(self, event, ...)

   elseif t == "nil" then
    print("Notice: Event '" .. event .. "' was subscribed to, but not assigned any action.")
    return
    
   else
    print("Warning: function AST_RegisterEvent(frame, eventName, func)")
    print("   - Encountered data type for event function other than 'function' or 'nil'.")
    print("     Type: " .. t .. ", Value: " .. tostring(item.func) .. ".")
   end
  end
 end
 
 if not eventWasHandled then
  print("Warning: AST_MainEventHandler(self, event, ...)")
  print(".  - Event '" .. event .. "' was fired, but not handled because it is unrecognised.")
  print("   - If you see this message, you might want to create handlers to deal with those events.")
 end
end
My question is: Why is there no payload/is there anything that I am doing wrong? I can't find anything online regarding this event than type and text should be the payload for this event.

Last edited by AreGee : 06-02-20 at 09:09 PM.
  Reply With Quote
06-02-20, 07:09 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,727
Where is your frame:OnEvent() part?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-02-20, 08:13 PM   #3
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,216
Have you tried printing the event sent to AST_Event_LUAWarning just in case you have somehow managed to AST_RegisterEvent() another event with no payload to that function association?

From the /API documents:

Code:
ScriptWarnings->Events

LuaWarning
	LiteralName = LUA_WARNING

PAYLOAD:
	warnType, Type = number, Nilable = false
	warningText, Type = string, Nilable = false
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-02-20, 08:55 PM   #4
AreGee
A Defias Bandit
Join Date: Jun 2020
Posts: 3
Wow! I seriously didn't expect to get answers that fast! Thank you!

Regarding printing the name of the event, I just printed the value that is passed in the event parameter. I do indeed get the correct event name, LUA_WARNING.

I also tried to do a:

Code:
print(...)
That prints '0 (null)'.

The fact I do get a number and a string (nil - abscence of a string rather) like I am expecting makes me think Blizzard is hiding the information on purpose, but that does sound weird to me. Everything works perfectly for any other event, so I don't understand what is going on

EDIT: I just noticed in your comment that it does say that neither of the values is nilable... That makes this even weirder.

Here is the frame:OnEvent() part (sorry I didn't think it was important since the correct function does get called:

Code:
local function AST_CreateWindowFrame()
 _V.MainWindowFrame = CreateFrame("Frame", _V.C.AddOnName, UIParent)

 local frame = _V.MainWindowFrame
 
 frame:SetScript("OnEvent", _V.F.MainEventHandler)

 local RegEvt = _V.F.RegisterEvent

 RegEvt(frame, "ADDON_ACTION_BLOCKED", nil)
 RegEvt(frame, "ADDON_ACTION_FORBIDDEN", nil)
 RegEvt(frame, "LUA_WARNING", AST_Event_LUAWarning)
 RegEvt(frame, "SAVED_VARIABLES_TOO_LARGE", nil)
 RegEvt(frame, "ADDONS_UNLOADING", nil)

 RegEvt(frame, "ADDON_LOADED", AST_Event_AddOnLoaded)

 RegEvt(frame, "PLAYER_ENTERING_WORLD", AST_Event_PlayerEnteringWorld)

 RegEvt(frame, "AUCTION_HOUSE_SHOW", nil)
 RegEvt(frame, "AUCTION_HOUSE_CLOSED", nil)
 
 frame:SetFrameStrata(_V.C.MainFrameStrata)
 frame:SetWidth(_V.F.GetConfigItem("MainFrame Width"))
 frame:SetHeight(_V.F.GetConfigItem("MainFrame Height"))
 frame:SetPoint("CENTER", UIParent, "CENTER")

 frame.skeleton = frame:CreateTexture("AuctionScanner_Skeleton", "BORDER")
 frame.skeleton:SetAllPoints()
-- frame.skeleton:SetTexture("Interface/AUCTIONFRAME/AuctionHouseBackgrounds")
-- local top, bottom, left, right = 0.39, 0.79, 0.18, 0.47
-- frame.skeleton:SetTexCoord(left, top, left, bottom, right, top, right, bottom)
 frame.skeleton:SetColorTexture(0, 0, 0, 0.25)

 frame.title = frame:CreateFontString("AuctionScanner_Title", "OVERLAY", "GameFontNormal")
 frame.title:SetPoint("TOP", 0, 0)
 frame.title:SetText("Auction Scanner Tool")
 
 -- Make sure you can only run this function ONCE --
 _V.F.CreateWindowFrame = _V.F.dummy
end

Last edited by AreGee : 06-02-20 at 09:05 PM.
  Reply With Quote
06-02-20, 09:07 PM   #5
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,216
Try:
Code:
local function AST_Event_LUAWarning(self, event, ...)
    HandleLuaWarning(...)
end
or possibly:
Code:
local function AST_Event_LUAWarning(self, event, ...)
	local warnType, warningText = ...
	if warnType == LUA_WARNING_TREAT_AS_ERROR -- 0
		HandleLuaWarning(...)
	else
		print("Warning: LUA_WARNING, type: " .. tostring(warnType) .. ", text: " .. warningText)
	end
end
A warnType of 0 appears to mean a script error rather than one coming from the game engine.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-02-20 at 09:27 PM.
  Reply With Quote
06-02-20, 10:06 PM   #6
AreGee
A Defias Bandit
Join Date: Jun 2020
Posts: 3
Thank you for pointing me in the right direction!

I think you are right, although the function HandleLuaWarning(...) did not do anything visible at all. It did not stop execution of the script either, so it is definitely a valid function.

I will leave in your modified code for now as it seems that you are right that the code 0 is a script error. Now I need to locate where I put in those mistakes... I think I put them in on purpose but I don't remember where, lol.

EDIT:

A bit of research reveals the HandleLuaWarning function:

Code:
function HandleLuaWarning(warnType, warningMessage)
	local cvarName = "scriptWarnings";
	if ( warnType == LUA_WARNING_TREAT_AS_ERROR ) then
		cvarName = "scriptErrors";
	end

	DisplayMessageInternal(cvarName, warnType, warningMessage, MESSAGE_TYPE_WARNING);
end
So it seems all you need to do is your first suggestion to only call the function to handle the error/warning as the test is done in there anyway.

Either way, a warning message of nil is not much of help anyway.

EDIT 2:
Also, I found that the reason I never get any error messages no matter why, apart from this problem, is because WoW does not display script errors per default.

It can be turned on by the following, but I assume this is not new to anyone here:

Code:
/console scriptErrors 1
It was a script error, by the way. A part that I left out where I copy pasted and forgot to change the name of a variable made me call a function from nil.

I have a theory that script errors are treated like they are (0 (null)) because you can enable them like above to have the game show you the error message anyway. After all the name is LUA_WARNINGS, not -ERRORS.

My final version, for completeness:

Code:
local function AST_Event_LUAWarning(self, event, ...)
 local warnType, warningText = ...
 if warnType == LUA_WARNING_TREAT_AS_ERROR then
  print("ERROR: To see errors, type '/console scriptErrors 1' in the chat window, then reload your AddOn.")
 else
  print("Warning: " .. event .. ", type: " .. tostring(warnType) .. ", text: " .. tostring(warningText))
 end
end

Last edited by AreGee : 06-02-20 at 10:43 PM.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Event LUA_WARNING payload 0 and NULL

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off