Content deleted Content added
Jackmcbarn (talk | contribs) re |
→JSON: Reply |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1:
{{permanently protected}}
== Request ==
Line 4 ⟶ 5:
:{{ping|MSGJ}} Done. Add <code><nowiki>|softfail=</nowiki></code> to the invocation you want this for. [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 00:35, 15 January 2021 (UTC)
::Sorry it's not working yet. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 10:14, 15 January 2021 (UTC)
<code><nowiki>{{#invoke:Data|Module:Data/
:::{{ping|MSGJ}} I see. It's because <code>table.concat</code> doesn't respect metamethods. Fixed now. [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 19:04, 16 January 2021 (UTC)
::::That's great [[User:Jackmcbarn|Jackmcbarn]], thanks! Do we actually need two different ways to display the error, or could the softfail be used for all? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 11:22, 17 January 2021 (UTC)
:::::{{ping|MSGJ}} I intend for <code>softfail</code> to mean "I know this might fail and I'm going to handle it if it does". If softfail were the default, it would be easy for a lookup to fail in a template where the author didn't expect it, but also in such a way that no tracking category gets added (e.g., inside the condition of a #if). The tracking category from a script error is "stickier", so it being the default means that any coding mistakes will for sure result in a categorization so we can find and fix them. [[User:Jackmcbarn|Jackmcbarn]] ([[User talk:Jackmcbarn|talk]]) 17:00, 17 January 2021 (UTC)
::::::Fair enough, and thanks again! — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 22:35, 17 January 2021 (UTC)
== JSON ==
Would it be possible to develop a version of this module which would read a JSON pages? Or do we have something that can do this already? — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 06:54, 15 July 2023 (UTC)
:Well, I attempted to modify this module but was unsuccessful. So I created a bespoke module at [[Module:Women in Green event]] which serves my immediate needs. If this ever gets implemented here, then that module could be deleted. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 12:14, 29 September 2023 (UTC)
::{{ping|MSGJ}} I've decided to give this a crack in the sandbox. The module will attempt to load the page as if it was a module page by default, and if this doesn't work, it'll instead try to load it as a Json page. If neither of these works, it throws an error like current functionallity (yet worded to mean something a bit more specific for this case). I don't imagine this pcall logic will cause any overhead (and could even maybe be made smart by checking if the input is in the Module namespace before even bothering trying to do loadData). You can see a test of it [[Special:Permalink/1178703748|here]]. Does this seem fine? [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 09:51, 5 October 2023 (UTC)
:::Thanks Aidan! Can you see why [[Module talk:Data/testcases]] is not working? To get this working in [[Module:Women in Green event]] I had to use <code>tonumber</code> to convert the 1 to a number. (I don't understand why because I used "1" in the JSON file, which should be a string.) It seems this module can only handle keys which are strings. — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 11:23, 5 October 2023 (UTC)
::::The issue here is that the JSON loader is probably automatically converting these to number keys for whatever reason. I've fixed it in this module by going for the numbered key if and only if it has a tonumber evaluation and the string key returns nil, which fixes your testcase. [[User:Aidan9382|Aidan9382]] <sub>([[User talk:Aidan9382|talk]])</sub> 11:50, 5 October 2023 (UTC)
:::::Thanks, that looks good — Martin <small>([[User:MSGJ|MSGJ]] · [[User talk:MSGJ|talk]])</small> 12:01, 5 October 2023 (UTC)
|