I'm trying to avoid throwing errors whenever the cache gets invalidated which tends to happen after patches. The main problem for me is that during OnEnable various strings are still missing for things like skills and the names of your mounts. So this post is one half explaining how I've tried to work around it and one half looking for good ideas from others. One big caveat is that I don't have any UI besides the options UI. If I did have frames up on screen at load I'd probably have had to do something else.
So the first thing was that I couldn't find a suitable event to listen for in these cases where we have to try to reinitialize again later. One way might have been to just register a grab bag of common events (combat log, chat messages, etc) and try to reinitialize every time when we get one, unregistering once we finally succeeded.
I wasn't crazy about that so instead I went with trying to catch the main entry points into my addons and adding init checks there. So, in my chat command handler I'll output an error message to try again later if I still can't initialize and only execute the command if its safe.
When calling RegisterOptionsTable, instead of passing the table we instead pass a GetOptions function. That function can then do the same kind of init check and in the error case put up a different options ui with the same kind of warning.
For all the keybindings, I have them go through a wrapper like so:
function Foo:SafeCall(fn, ...)
if (init_check) then
return fn(self, ...);
output error message etc
Of course, it turns out that one of my friends still got errors because he was using a macro that called the functions directly using /run, but I'm thinking of just punting on that case since I already had a chat command to support what he was trying to do.
Anyway, I'm interested in how others have tried to work around this problem.
I read your whole post, and I'm not really sure what specific problem(s) you're trying to "work around". You mentioned that "strings for skill names" aren't available when OnEnable happens; what skills are you talking about (eg. skills in your spell book? boss mob skills?) and where are you trying to get their names from? I also have no idea what RegisterOptionsTable has to do with skill names, or what information is still unavailable by the time you're loaded in enough to type in a chat command. Could you be more specific about what your addon is supposed to do, what API functions you're having problems getting information from, what events you're trying to listen for, etc.?
If the cache has been deleted or invalidated then GetCompanionInfo and GetSkillLineInfo will both return nil values for the name. RegisterOptionsTable itself doesn't have anything to with skill names per se, but I populate dropdowns in my options UI with lists of mounts. If I don't have those names, I really don't have anything I can show. I need to know the users riding skill for example to slot the death knight mounts into the correct category.
You asked "what information is still unavailable by the time you're loaded in enough to type in a chat command"; actually, by that point I think the information is probably available. The problem is, that as an addon, how do you know you're loaded in enough to type in a chat command? That's what I was talking about in terms of not finding a suitable event to listen for. PLAYER_ENTERING_WORLD looked a candidate, but it happens too early.
Since I expect the info to probably be available when the user types in a chat command, that's what led to my change in approach. I just wait for the user to call us to finish the initialization. So, it was about seeing if I could make changes in a minimal number of places as to catch usage of our addon.
I thought the function pointers stuff for bindings and the way you can pass a function to RegisterTableOptions could be interesting for other addon writers who, like me, are still crawling up the learning curve. And at the same time maybe see if someone had a better mousetrap.
I noticed that after patch day or deleting the cache - I eat a disconnect trying to login on my characters and then things work like normal (after the cache is filled with some information). I did explain this that there are uncached items and stuff, overloading the server with queries.
I would assume that there are more addons out there loading / trying to load items, skills, abilities on load addon and not when the frame is opened first.
There are a ton of poorly-coded addons out there trying to do things way too early. After a patch, I do an end run around them all by
1) moving Interface and WTF aside
2) logging into most of my characters. opening bags, opening bank, opening tradeskills and waiting for the windows to sort themselves, opening talent window, etc.
3) exiting game, removing the generated stub Interface and WTF, moving the real ones back into place
Whole process takes about 5-8 minutes for maybe 8 toons. Never had any cache-related brokenness after that due to sloppy coding. No, none of that should be necessary in a perfect world, but it's worth it just to avoid headache and annoyance for the rest of patch day.
It's really not that hard to deal with a cleared cache. The key to all of it is not asking for cached data until you truly *need* it. If you do that, 95% of the time the user has encountered the item/spell/whatever and it has been cached.
If the cache has been deleted or invalidated then GetCompanionInfo and GetSkillLineInfo will both return nil values for the name. RegisterOptionsTable itself doesn't have anything to with skill names per se, but I populate dropdowns in my options UI with lists of mounts.
Do what Tekkub said, and generate the options when the user requests the options, not the moment your addon loads.
The problem is, that as an addon, how do you know you're loaded in enough to type in a chat command?
The addon doesn't need to know, because the user cannot enter chat commands before the client is finished loading, because they're staring at a loading screen with no access to the chat system. By the time the user does have access to the chat system and can enter a chat command or open an options panel, both of the functions you named will return valid data, and no problem exists.