Talk:Recommendations for gadget developers on Wikimedia wikis

Cater for the situation where these elements do not exist
I actually consider the  more of an antipattern than. I encountered multiple times that someone reports that a gadget doesn’t do anything, and when I asked them for the stack trace, it turned out that there wasn’t any. These are often caused by such structures: (jQuery is especially prone to such issues, as its signature doesn’t make it obvious that there’s a no-op when the selector doesn’t match).

There are three acceptable solutions IMO: Tacsipacsi (talk) 02:12, 11 January 2023 (UTC)
 * Provide an actual fallback if possible. For example, if there’s no, insert the node to the beginning of the content, or wherever it makes sense.
 * Replace the  with a   call if no actual fallback can be provided but the gadget is still useful without this part. The gadget functionality will be partial if   goes away, but the cause will appear in the console, and other parts of the gadget will continue to work.
 * Don’t care, i.e. do what you put in . If the gadget cannot do anything useful without , fail fast and loud so that someone quickly notices it, and the gadget can be fixed or disabled.


 * Thanks for adding the note about logging and the fallback call. However, I still think in cases when no fallback is possible and the gadget cannot provide any – not even degraded – functionality without a given element (e.g. MediaWiki:Gadget-purgetab.js can do nothing without ), it is appropriate and desirable to error out – if not many users use the given gadget, the “log spam” (which is not really spam, since it’s about a real issue) won’t be that big; if many users use it, developers have just broken the wiki for many users. It may not be their task to fix it, but gadget maintainers have no way to notice the issue other than getting feedback either from people watching the logs, or from upset users. —Tacsipacsi (talk) 00:06, 13 January 2023 (UTC)
 * Throwing an error adds it production logs. If those happen current practice is to follow this guideline. If the goal is to log an error to the JavaScript console you can use mw.log.warn or mw.log.error. would suggesting use of those be be better?
 * If gadget developers are not looking at those logs wouldn't it be better to find a way to make those more visible so they are handled by the gadgets themselves? For example perhaps there should be a reportGadgetError function local to the wiki that reports in a non spammy way that there's a gadget error so users can report these to the gadget developer? Jdlrobson (talk) 00:36, 13 January 2023 (UTC)