Show value warnings in debug#4678
Conversation
|
Hey there! Thanks for helping Mudlet improve. 🌟 Test versionsYou can directly test the changes here:
No need to install anything - just unzip and run. |
|
Thinking about it, it might be wise to merge this not into development but into #4661 so we don't get massive conflicts. |
| } | ||
| // No documentation available in wiki - internal function | ||
| // See also: verifyBoolean | ||
| // Raises a Lua error in case of an API usage mistake |
There was a problem hiding this comment.
Good idea, but rename these to type and value errors instead for differentiation
|
|
||
| if (!mudlet::self()->getAvailableFonts().contains(font, Qt::CaseInsensitive)) { | ||
| lua_pushnil(L); | ||
| lua_pushfstring(L, "font '%s' is not available)", font.toUtf8().constData()); |
There was a problem hiding this comment.
nice hard-to-spot bug again eliminated in passing by standardizing (the message ended in ) but should not)
There was a problem hiding this comment.
To avoid confusion would it be better to change font to fontName?
There was a problem hiding this comment.
I don't think anyone would actually really be so confused about this that they'd make an error to be honest
I hear the thoughts about conflicts, but I tried to keep #4661 to type errors only, trying not to touch value errors at all. |
src/TLuaInterpreter.cpp
Outdated
| if (result.first == 2) { | ||
| lua_pushnil(L); | ||
| lua_pushfstring(L, "current selection invalid in window \"%s\"", windowName.toUtf8().constData()); | ||
| returnWrongArgumentType(L, __func__, QStringLiteral(R"(current selection invalid in window "%1")").arg(windowName)); |
There was a problem hiding this comment.
Can we agree to just use 'single quotes' inside the string, and do away with R"( syntax?
There was a problem hiding this comment.
I don't mind the syntax but I'm okay with changing to single quotes
There was a problem hiding this comment.
Some use R"( currently, some escape \" every single quote, some do single quotes, some no quotes at all.
It's just a wild mess and rather incoherent. No obvious direction which style to use for new messages.
I would vote for porting \" and R"( to single quotes, then later add them where no were before.
This way 'argument values' are clearly distinct from parts of the sentence even for casual players.
There was a problem hiding this comment.
TBH I am not a fan of the C++ raw string literal form - partly because it broke when used with texts for translations - though that has now been fixed - and I am conditioned to use the escape form - though perhaps I can eventually be deconditioned/deprogrammed away from that. As it is the ' does work better within Lua erorr message, it is just that as a C/C++ coder I am also programmed to think of that delimiter only for single chars so forgot to use that form.
🤯
|
Watch out as these messages now use %1 syntax whereas type errors use %d and %s instead. edit: Any idea how to unify? |
|
Unify - hmm, not without adding overhead I don't think. It's not an issue that bites us in practice. |
src/TLuaInterpreter.cpp
Outdated
| @@ -3179,12 +3122,7 @@ int TLuaInterpreter::saveProfile(lua_State* L) | |||
| return 2; | |||
| } else { | |||
| auto message = QString("Couldn't save %1 to %2 because: %3").arg(host.getName(), std::get<1>(result), std::get<2>(result)); | |||
There was a problem hiding this comment.
ℹ️ Needs to be switched from a QString to a QStringLiteral to match our coding style/guide IMHO.
There was a problem hiding this comment.
Maybe but not in scope really
src/TLuaInterpreter.cpp
Outdated
| lua_pushnil(L); | ||
| lua_pushfstring(L, "setBackgroundColor: bad argument #%d value (red value needs to be between 0-255, got %d!)", s, r); | ||
| return 2; | ||
| return warnArgumentValue(L, __func__, QStringLiteral("bad argument #%1 value (red value needs to be between 0-255, got %2!)").arg(s, r)); |
There was a problem hiding this comment.
Since you are now using QString::arg(...) you have got to either use a separate .arg(int).arg(int) form or convert them to text before one of the QString::arg(...) overloads thinks that the second number is a field width or number base or sommat - note that this applies to all cases where there is more than one argument and the second (and possibly higher) arguments are numbers but I am only pointing out this one!
| return warnArgumentValue(L, __func__, QStringLiteral("bad argument #%1 value (red value needs to be between 0-255, got %2!)").arg(s, r)); | |
| return warnArgumentValue(L, __func__, QStringLiteral("bad argument #%1 value (red value needs to be between 0-255, got %2!)").arg(QString::number(s), QString::number(r))); |
There was a problem hiding this comment.
It's good for mixed argument types but not in general https://github.com/Mudlet/Mudlet/blob/development/.github/CONTRIBUTING.md#use-argarg1-arg2-instead-of-argarg1argarg2
There was a problem hiding this comment.
Then again, some of these are like (auto, auto) 😕
There was a problem hiding this comment.
Oh whoopsie, will switch to QString::number(x) then instead.
These lines now seem to get rather long and unwieldy.
But I hesitate to split it into 2-3 every single time.
|
Would it look better if the text began with something like: Given that you are reporting the function it might be worth checking the format compared to the other ones (the |
|
You bring up a valid reason, I don't think we should do it - for aesthetic reasons I think an orange Lua is enough and self explanatory. Could even trim Lua OK to just Lua in green. |
|
Well, as I say, there are green |
|
OK, this looks good to me now, please review. |
src/Host.cpp
Outdated
| pC->resize(width, height); | ||
| pC->move(x, y); | ||
| return {false, QStringLiteral("miniconsole \"%1\" exists already. moving/resizing \"%1\".").arg(name)}; | ||
| return {false, QStringLiteral("miniconsole \"%1\" exists already: moving/resizing \"%1\".").arg(name)}; |
There was a problem hiding this comment.
I don't understand this change. The : makes this confusing. Why did the . not suffice? There are more changes like this I don't understand.
There was a problem hiding this comment.
It's proper grammar to use : to extend the thought instead of starting a separate sentence - looks better on the eye.
What other ones didn't you follow?
There was a problem hiding this comment.
"exists already" or "already exists" - I can't put my finger on it but the second sounds better - especially as an introduction to what follows after the :
There was a problem hiding this comment.
I agree, latter sounds better.
There was a problem hiding this comment.
No idea how : connects the 2 sentences. I would expect information on where or how the name exists already.
I would connect the sentences with "therefore" or leave them separated or drop the second completely.
|
I am not so sure that the double use of |
|
Where are there cases with more than one? |
|
One ':' after "LUA" and another after "createLabelMainWindow"! |
|
That doesn't seem like an issue to me. Why add all sorts of different symbols just to be different |
Kebap
left a comment
There was a problem hiding this comment.
Don't like the ':' added: The rest of the PR is great
(See how : doesn't make sense above. )
src/Host.cpp
Outdated
| pC->resize(width, height); | ||
| pC->move(x, y); | ||
| return {false, QStringLiteral("miniconsole \"%1\" exists already. moving/resizing \"%1\".").arg(name)}; | ||
| return {false, QStringLiteral("miniconsole \"%1\" exists already: moving/resizing \"%1\".").arg(name)}; |
There was a problem hiding this comment.
No idea how : connects the 2 sentences. I would expect information on where or how the name exists already.
I would connect the sentences with "therefore" or leave them separated or drop the second completely.
|
Feedback applied |
This was introduced in the recent "Show value warnings in debug" PR Mudlet#4678. I believe I have found all of use of `%d` (or `%s`) instead of `%1` or higher numbers in this file. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
) This was introduced in the recent "Show value warnings in debug" PR #4678. I believe I have found all of use of `%d` (or `%s`) instead of `%1` or higher numbers in this file. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>
…dlet#4765) This was introduced in the recent "Show value warnings in debug" PR Mudlet#4678. I believe I have found all of use of `%d` (or `%s`) instead of `%1` or higher numbers in this file. Signed-off-by: Stephen Lyons <slysven@virginmedia.com>

Brief overview of PR changes/additions
Show errors (or warnings actually?) in debug
Motivation for adding to Mudlet
So these messages aren't lost if scripts don't do their error checking.
Don't show to main window because it's not important enough of a message to start spamming with.
Other info (issues closed, discussion etc)
Start addressing #4559.
PR open for review against a few functions, once approved I'll work on the rest.