Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There are 17 places where "IConsoleError" can be used instead of "IConsolePrintF". #8853

Closed
James103 opened this issue Mar 12, 2021 · 5 comments · Fixed by #9359
Closed

There are 17 places where "IConsoleError" can be used instead of "IConsolePrintF". #8853

James103 opened this issue Mar 12, 2021 · 5 comments · Fixed by #9359
Labels
enhancement good first issue

Comments

@James103
Copy link
Contributor

@James103 James103 commented Mar 12, 2021

Version of OpenTTD

9c5a7d3

Expected result

The function IConsoleError behaves exactly the same as using IConsolePrintF(CC_ERROR, "ERROR: %s", string);, but is shorter and more concise.

OpenTTD/src/console.cpp

Lines 168 to 171 in 9c5a7d3

void IConsoleError(const char *string)
{
IConsolePrintF(CC_ERROR, "ERROR: %s", string);
}

Therefore, IConsoleError(string) should in general be used instead of IConsolePrintF(CC_ERROR, "ERROR: %s", string).

Actual result

The following 14 occurrences of IConsolePrintF(CC_ERROR, "ERROR: %s", string) still exist:

IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
}
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);

IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
}
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);

default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
}
} else {
IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);

IConsolePrintF(CC_ERROR, "ERROR: Silly boy, you can not %s yourself!", ban ? "ban" : "kick");

IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE " characters.", kick_message_length);

IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE " characters.", kick_message_length);

IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);

IConsolePrintF(CC_ERROR, "Company %d requires a password to join.", company_id + 1);

IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);

IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);

IConsolePrintF(CC_ERROR, "ERROR: alias is of special type, please see its execution-line: '%s'", alias->cmdline);

Additionally, there are 3 additional occurrences of IConsolePrint(CC_ERROR, "ERROR: %s", string):

IConsolePrint(CC_ERROR, "Tile does not exist");

IConsolePrint(CC_ERROR, "Tile does not exist");

IConsolePrint(CC_ERROR, "Saving map failed");

Steps to reproduce

Look in the source of commands.cpp for the above occurrences.

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Mar 12, 2021

Have you ever considered making Pull Requests yourself? These kind of things are easy things to start with in a codebase like OpenTTD, and it seems you have a good grasp on what should happen/change?

Possibly also easier for yourself, as making these changes in code would have been faster than writing this ticket :D

Not saying you have to btw, I am perfectly fine with these tickets; I was just wondering :)

@TrueBrain TrueBrain added enhancement good first issue labels Mar 12, 2021
@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Mar 12, 2021

PS : not all cases you highlight are "ERROR: " atm. But by the looks, most should be. So it is a two-for-oner :D

Example: IConsolePrint(CC_ERROR, "Saving map failed"); <- currently doesn't contain the word ERROR: :)

@TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Mar 12, 2021

IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file); currently cannot be replaced with IConsoleError, as it doesn't use a plain string. I guess we need a IConsoleErrorF instead. Would make sense to me, to have that.

Looking over the list, all instances except for the last 3 are this, and this is also most likely the reason they are not IConsoleError yet. The last three are just silly, so they can be fixed easily :)

@AyushRaj8271
Copy link

@AyushRaj8271 AyushRaj8271 commented May 16, 2021

Is this issue stilll available ?

@AyushRaj8271
Copy link

@AyushRaj8271 AyushRaj8271 commented May 16, 2021

I would like to work on it !!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants