Jump to content

Module talk:Data

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Aidan9382 (talk | contribs) at 09:51, 5 October 2023 (JSON: Reply). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Request

@Jackmcbarn: I know you're not too active at the moment, but I have a request. Would it be possible to update the code so that it will fail gracefully (without script errors) if key1 does not exist in the data module? At the moment I have no way to see if a value is defined without causing the script error. Thanks and hope to see you back soon! — Martin (MSGJ · talk) 22:24, 14 January 2021 (UTC)[reply]

@MSGJ: Done. Add |softfail= to the invocation you want this for. Jackmcbarn (talk) 00:35, 15 January 2021 (UTC)[reply]
Sorry it's not working yet. — Martin (MSGJ · talk) 10:14, 15 January 2021 (UTC)[reply]

{{#invoke:Data|Module:Data/List config|Q1234|c1|softfail=y}} -> Lua error in package.lua at line 80: module 'Module:Data/List config' not found.

@MSGJ: I see. It's because table.concat doesn't respect metamethods. Fixed now. Jackmcbarn (talk) 19:04, 16 January 2021 (UTC)[reply]
That's great Jackmcbarn, thanks! Do we actually need two different ways to display the error, or could the softfail be used for all? — Martin (MSGJ · talk) 11:22, 17 January 2021 (UTC)[reply]
@MSGJ: I intend for softfail 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. Jackmcbarn (talk) 17:00, 17 January 2021 (UTC)[reply]
Fair enough, and thanks again! — Martin (MSGJ · talk) 22:35, 17 January 2021 (UTC)[reply]

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 (MSGJ · talk) 06:54, 15 July 2023 (UTC)[reply]

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 (MSGJ · talk) 12:14, 29 September 2023 (UTC)[reply]
@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 begins with "Module:" before even bothering trying to do loadData). You can see a test of it here. Does this seem fine? Aidan9382 (talk) 09:51, 5 October 2023 (UTC)[reply]