Skip to content

Show value warnings in debug#4678

Merged
vadi2 merged 54 commits intoMudlet:developmentfrom
vadi2:show-errors-in-debug
Feb 1, 2021
Merged

Show value warnings in debug#4678
vadi2 merged 54 commits intoMudlet:developmentfrom
vadi2:show-errors-in-debug

Conversation

@vadi2
Copy link
Copy Markdown
Member

@vadi2 vadi2 commented Jan 25, 2021

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.

show-errors-in-debug

@vadi2 vadi2 requested a review from a team as a code owner January 25, 2021 08:34
@vadi2 vadi2 requested review from a team January 25, 2021 08:34
@add-deployment-links
Copy link
Copy Markdown

add-deployment-links bot commented Jan 25, 2021

Hey there! Thanks for helping Mudlet improve. 🌟

Test versions

You can directly test the changes here:

No need to install anything - just unzip and run.
Let us know if it works well, and if it doesn't, please give details.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 25, 2021

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());
Copy link
Copy Markdown
Contributor

@Kebap Kebap Jan 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice hard-to-spot bug again eliminated in passing by standardizing (the message ended in ) but should not)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid confusion would it be better to change font to fontName?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is discussed in #4638

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think anyone would actually really be so confused about this that they'd make an error to be honest

@Kebap
Copy link
Copy Markdown
Contributor

Kebap commented Jan 25, 2021

Thinking about it, it might be wise to merge this not into development but into #4661 so we don't get massive conflicts.

I hear the thoughts about conflicts, but I tried to keep #4661 to type errors only, trying not to touch value errors at all.
Would rather keep these issues separated not to inflate scope and make reviews even more complicated for others.

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));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we agree to just use 'single quotes' inside the string, and do away with R"( syntax?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind the syntax but I'm okay with changing to single quotes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

🤯

@Kebap
Copy link
Copy Markdown
Contributor

Kebap commented Jan 25, 2021

Watch out as these messages now use %1 syntax whereas type errors use %d and %s instead.

edit: Any idea how to unify?

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 26, 2021

Unify - hmm, not without adding overhead I don't think. It's not an issue that bites us in practice.

@@ -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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ Needs to be switched from a QString to a QStringLiteral to match our coding style/guide IMHO.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe but not in scope really

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));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

Suggested change
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)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Need to review!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then again, some of these are like (auto, auto) 😕

Copy link
Copy Markdown
Contributor

@Kebap Kebap Jan 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 26, 2021

Would it look better if the text began with something like:
LUA WARN: or LUA WARNING:
instead of Lua:
so that it is similar in form to the LUA OK:

Given that you are reporting the function it might be worth checking the format compared to the other ones (the LUA ERROR ones) that also report the function to see if that can be done in a more consistent style...

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 26, 2021

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.

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 26, 2021

Well, as I say, there are green LUA OKs and red LUA ERRORs so why can't we have orange LUA WARN(ING)s?

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 29, 2021

We also have warnings coming from Host.cpp where they're used as-is, for example:

image

And then the __func__ doesn't work quite so hot anymore 😅

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 29, 2021

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)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"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 :

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, latter sounds better.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 30, 2021

#4678 (comment)

I am not so sure that the double use of : works so well there - what is on the left side of one is an introduction or something that is given more detail on the right side - but how does that work when there is more that one? See https://en.wikipedia.org/wiki/Colon_(punctuation)

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 30, 2021

Where are there cases with more than one?

@SlySven
Copy link
Copy Markdown
Member

SlySven commented Jan 30, 2021

LUA: createLabelMainWindow: label "svo.riftlabel" exists already.

One ':' after "LUA" and another after "createLabelMainWindow"!

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 30, 2021

That doesn't seem like an issue to me. Why add all sorts of different symbols just to be different

Copy link
Copy Markdown
Contributor

@Kebap Kebap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vadi2
Copy link
Copy Markdown
Member Author

vadi2 commented Jan 31, 2021

Feedback applied

@vadi2 vadi2 merged commit 3929ed9 into Mudlet:development Feb 1, 2021
@vadi2 vadi2 deleted the show-errors-in-debug branch February 1, 2021 08:07
SlySven added a commit to SlySven/Mudlet that referenced this pull request Feb 8, 2021
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>
SlySven added a commit that referenced this pull request Feb 8, 2021
)

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>
Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
Chris7 pushed a commit to Chris7/Mudlet that referenced this pull request Jan 2, 2022
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants