summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-06-12 21:07:04 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-06-13 15:25:31 +0200
commitefd4ba4797c90a4e624a3f039c84a2321641dab4 (patch)
tree4ee3e3c966df67b6c9703a683bf9731eb52a5a44 /src
parentde49727ae81dd1aa999e8090f736844bbfd1481d (diff)
downloadopenttd-efd4ba4797c90a4e624a3f039c84a2321641dab4.tar.xz
Change: unify the style of console error messages and convert to fmt
Always start with a capital, do not add "ERROR: " in front of it.
Diffstat (limited to 'src')
-rw-r--r--src/console.cpp21
-rw-r--r--src/console_cmds.cpp106
-rw-r--r--src/error_gui.cpp5
-rw-r--r--src/settings.cpp4
4 files changed, 66 insertions, 70 deletions
diff --git a/src/console.cpp b/src/console.cpp
index 11a3d4771..82e6e04bf 100644
--- a/src/console.cpp
+++ b/src/console.cpp
@@ -229,7 +229,7 @@ static std::string RemoveUnderscores(std::string name)
/* static */ void IConsole::AliasRegister(const std::string &name, const std::string &cmd)
{
auto result = IConsole::Aliases().try_emplace(RemoveUnderscores(name), name, cmd);
- if (!result.second) IConsoleError("an alias with this name already exists; insertion aborted");
+ if (!result.second) IConsolePrint(CC_ERROR, "An alias with the name '{}' already exists.", name);
}
/**
@@ -259,7 +259,7 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
Debug(console, 6, "Requested command is an alias; parsing...");
if (recurse_count > ICON_MAX_RECURSE) {
- IConsoleError("Too many alias expansions, recursion limit reached. Aborting");
+ IConsolePrint(CC_ERROR, "Too many alias expansions, recursion limit reached.");
return;
}
@@ -305,8 +305,8 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
int param = *cmdptr - 'A';
if (param < 0 || param >= tokencount) {
- IConsoleError("too many or wrong amount of parameters passed to alias, aborting");
- IConsolePrintF(CC_WARNING, "Usage of alias '%s': %s", alias->name.c_str(), alias->cmdline.c_str());
+ IConsolePrint(CC_ERROR, "Too many or wrong amount of parameters passed to alias.");
+ IConsolePrint(CC_HELP, "Usage of alias '{}': {}", alias->name, alias->cmdline);
return;
}
@@ -325,7 +325,7 @@ static void IConsoleAliasExec(const IConsoleAlias *alias, byte tokencount, char
}
if (alias_stream >= lastof(alias_buffer) - 1) {
- IConsoleError("Requested alias execution would overflow execution buffer");
+ IConsolePrint(CC_ERROR, "Requested alias execution would overflow execution buffer.");
return;
}
}
@@ -351,8 +351,7 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
for (cmdptr = cmdstr; *cmdptr != '\0'; cmdptr++) {
if (!IsValidChar(*cmdptr, CS_ALPHANUMERAL)) {
- IConsoleError("command contains malformed characters, aborting");
- IConsolePrintF(CC_ERROR, "ERROR: command was: '%s'", cmdstr);
+ IConsolePrint(CC_ERROR, "Command '{}' contains malformed characters.", cmdstr);
return;
}
}
@@ -367,7 +366,7 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
* of characters in our stream or the max amount of tokens we can handle */
for (cmdptr = cmdstr, t_index = 0, tstream_i = 0; *cmdptr != '\0'; cmdptr++) {
if (tstream_i >= lengthof(tokenstream)) {
- IConsoleError("command line too long");
+ IConsolePrint(CC_ERROR, "Command line too long.");
return;
}
@@ -388,7 +387,7 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
longtoken = !longtoken;
if (!foundtoken) {
if (t_index >= lengthof(tokens)) {
- IConsoleError("command line too long");
+ IConsolePrint(CC_ERROR, "Command line too long.");
return;
}
tokens[t_index++] = &tokenstream[tstream_i];
@@ -406,7 +405,7 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
if (!foundtoken) {
if (t_index >= lengthof(tokens)) {
- IConsoleError("command line too long");
+ IConsolePrint(CC_ERROR, "Command line too long.");
return;
}
tokens[t_index++] = &tokenstream[tstream_i - 1];
@@ -447,5 +446,5 @@ void IConsoleCmdExec(const char *cmdstr, const uint recurse_count)
return;
}
- IConsoleError("command not found");
+ IConsolePrint(CC_ERROR, "Command '{}' not found.", tokens[0]);
}
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp
index 8de5c4a3f..15422e420 100644
--- a/src/console_cmds.cpp
+++ b/src/console_cmds.cpp
@@ -96,7 +96,7 @@ static ConsoleFileList _console_file_list; ///< File storage cache for the conso
static inline bool NetworkAvailable(bool echo)
{
if (!_network_available) {
- if (echo) IConsoleError("You cannot use this command because there is no network available.");
+ if (echo) IConsolePrint(CC_ERROR, "You cannot use this command because there is no network available.");
return false;
}
return true;
@@ -111,7 +111,7 @@ DEF_CONSOLE_HOOK(ConHookServerOnly)
if (!NetworkAvailable(echo)) return CHR_DISALLOW;
if (!_network_server) {
- if (echo) IConsoleError("This command is only available to a network server.");
+ if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server.");
return CHR_DISALLOW;
}
return CHR_ALLOW;
@@ -126,7 +126,7 @@ DEF_CONSOLE_HOOK(ConHookClientOnly)
if (!NetworkAvailable(echo)) return CHR_DISALLOW;
if (_network_server) {
- if (echo) IConsoleError("This command is not available to a network server.");
+ if (echo) IConsolePrint(CC_ERROR, "This command is not available to a network server.");
return CHR_DISALLOW;
}
return CHR_ALLOW;
@@ -141,7 +141,7 @@ DEF_CONSOLE_HOOK(ConHookNeedNetwork)
if (!NetworkAvailable(echo)) return CHR_DISALLOW;
if (!_networking || (!_network_server && !MyClient::IsConnected())) {
- if (echo) IConsoleError("Not connected. This command is only available in multiplayer.");
+ if (echo) IConsolePrint(CC_ERROR, "Not connected. This command is only available in multiplayer.");
return CHR_DISALLOW;
}
return CHR_ALLOW;
@@ -154,7 +154,7 @@ DEF_CONSOLE_HOOK(ConHookNeedNetwork)
DEF_CONSOLE_HOOK(ConHookNoNetwork)
{
if (_networking) {
- if (echo) IConsoleError("This command is forbidden in multiplayer.");
+ if (echo) IConsolePrint(CC_ERROR, "This command is forbidden in multiplayer.");
return CHR_DISALLOW;
}
return CHR_ALLOW;
@@ -167,7 +167,7 @@ DEF_CONSOLE_HOOK(ConHookNoNetwork)
DEF_CONSOLE_HOOK(ConHookServerOrNoNetwork)
{
if (_networking && !_network_server) {
- if (echo) IConsoleError("This command is only available to a network server.");
+ if (echo) IConsolePrint(CC_ERROR, "This command is only available to a network server.");
return CHR_DISALLOW;
}
return CHR_ALLOW;
@@ -177,7 +177,7 @@ DEF_CONSOLE_HOOK(ConHookNewGRFDeveloperTool)
{
if (_settings_client.gui.newgrf_developer_tools) {
if (_game_mode == GM_MENU) {
- if (echo) IConsoleError("This command is only available in-game and in the editor.");
+ if (echo) IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
return CHR_DISALLOW;
}
return ConHookNoNetwork(echo);
@@ -222,12 +222,12 @@ DEF_CONSOLE_CMD(ConResetEnginePool)
}
if (_game_mode == GM_MENU) {
- IConsoleError("This command is only available in-game and in the editor.");
+ IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
return true;
}
if (!EngineOverrideManager::ResetToCurrentNewGRFConfig()) {
- IConsoleError("This can only be done when there are no vehicles in the game.");
+ IConsolePrint(CC_ERROR, "This can only be done when there are no vehicles in the game.");
return true;
}
@@ -372,10 +372,10 @@ DEF_CONSOLE_CMD(ConLoad)
_file_to_saveload.SetName(FiosBrowseTo(item));
_file_to_saveload.SetTitle(item->title);
} else {
- IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file);
+ IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
}
} else {
- IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
+ IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
}
return true;
@@ -396,10 +396,10 @@ DEF_CONSOLE_CMD(ConRemove)
const FiosItem *item = _console_file_list.FindItem(file);
if (item != nullptr) {
if (!FiosDelete(item->name)) {
- IConsolePrintF(CC_ERROR, "%s: Failed to delete file", file);
+ IConsolePrint(CC_ERROR, "Failed to delete '{}'.", file);
}
} else {
- IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
+ IConsolePrint(CC_ERROR, "'{}' could not be found.", file);
}
_console_file_list.InvalidateFileList();
@@ -441,10 +441,10 @@ DEF_CONSOLE_CMD(ConChangeDirectory)
case FIOS_TYPE_DIR: case FIOS_TYPE_DRIVE: case FIOS_TYPE_PARENT:
FiosBrowseTo(item);
break;
- default: IConsolePrintF(CC_ERROR, "%s: Not a directory.", file);
+ default: IConsolePrint(CC_ERROR, "{}: Not a directory.", file);
}
} else {
- IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file);
+ IConsolePrint(CC_ERROR, "{}: No such file or directory.", file);
}
_console_file_list.InvalidateFileList();
@@ -498,13 +498,13 @@ static bool ConKickOrBan(const char *argv, bool ban, const std::string &reason)
* would be reading from and writing to after returning. So we would read or write data
* from freed memory up till the segfault triggers. */
if (client_id == CLIENT_ID_SERVER || client_id == _redirect_console_to_client) {
- IConsolePrintF(CC_ERROR, "ERROR: You can not %s yourself!", ban ? "ban" : "kick");
+ IConsolePrint(CC_ERROR, "You can not {} yourself!", ban ? "ban" : "kick");
return true;
}
NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(client_id);
if (ci == nullptr) {
- IConsoleError("Invalid client");
+ IConsolePrint(CC_ERROR, "Invalid client ID.");
return true;
}
@@ -521,9 +521,9 @@ static bool ConKickOrBan(const char *argv, bool ban, const std::string &reason)
}
if (n == 0) {
- IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist" : "Client not found");
+ IConsolePrint(CC_DEFAULT, ban ? "Client not online, address added to banlist." : "Client not found.");
} else {
- IConsolePrintF(CC_DEFAULT, "%sed %u client(s)", ban ? "Bann" : "Kick", n);
+ IConsolePrintF(CC_DEFAULT, "%sed %u client(s).", ban ? "Bann" : "Kick", n);
}
return true;
@@ -545,7 +545,7 @@ DEF_CONSOLE_CMD(ConKick)
/* Reason for kicking supplied */
size_t kick_message_length = strlen(argv[2]);
if (kick_message_length >= 255) {
- IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE " characters.", kick_message_length);
+ IConsolePrint(CC_ERROR, "Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
return false;
} else {
return ConKickOrBan(argv[1], false, argv[2]);
@@ -569,7 +569,7 @@ DEF_CONSOLE_CMD(ConBan)
/* Reason for kicking supplied */
size_t kick_message_length = strlen(argv[2]);
if (kick_message_length >= 255) {
- IConsolePrintF(CC_ERROR, "ERROR: Maximum kick message length is 254 characters. You entered " PRINTF_SIZE " characters.", kick_message_length);
+ IConsolePrint(CC_ERROR, "Maximum kick message length is 254 characters. You entered {} characters.", kick_message_length);
return false;
} else {
return ConKickOrBan(argv[1], true, argv[2]);
@@ -636,7 +636,7 @@ DEF_CONSOLE_CMD(ConPauseGame)
}
if (_game_mode == GM_MENU) {
- IConsoleError("This command is only available in-game and in the editor.");
+ IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
return true;
}
@@ -658,7 +658,7 @@ DEF_CONSOLE_CMD(ConUnpauseGame)
}
if (_game_mode == GM_MENU) {
- IConsoleError("This command is only available in-game and in the editor.");
+ IConsolePrint(CC_ERROR, "This command is only available in-game and in the editor.");
return true;
}
@@ -731,24 +731,24 @@ DEF_CONSOLE_CMD(ConClientNickChange)
ClientID client_id = (ClientID)atoi(argv[1]);
if (client_id == CLIENT_ID_SERVER) {
- IConsoleError("Please use the command 'name' to change your own name!");
+ IConsolePrint(CC_ERROR, "Please use the command 'name' to change your own name!");
return true;
}
if (NetworkClientInfo::GetByClientID(client_id) == nullptr) {
- IConsoleError("Invalid client");
+ IConsolePrint(CC_ERROR, "Invalid client ID.");
return true;
}
std::string client_name(argv[2]);
StrTrimInPlace(client_name);
if (!NetworkIsValidClientName(client_name)) {
- IConsoleError("Cannot give a client an empty name");
+ IConsolePrint(CC_ERROR, "Cannot give a client an empty name.");
return true;
}
if (!NetworkServerChangeClientName(client_id, client_name)) {
- IConsoleError("Cannot give a client a duplicate name");
+ IConsolePrint(CC_ERROR, "Cannot give a client a duplicate name.");
}
return true;
@@ -766,28 +766,28 @@ DEF_CONSOLE_CMD(ConJoinCompany)
/* Check we have a valid company id! */
if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
- IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
+ IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
return true;
}
if (NetworkClientInfo::GetByClientID(_network_own_client_id)->client_playas == company_id) {
- IConsoleError("You are already there!");
+ IConsolePrint(CC_ERROR, "You are already there!");
return true;
}
if (company_id == COMPANY_SPECTATOR && NetworkMaxSpectatorsReached()) {
- IConsoleError("Cannot join spectators, maximum number of spectators reached.");
+ IConsolePrint(CC_ERROR, "Cannot join spectators, maximum number of spectators reached.");
return true;
}
if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
- IConsoleError("Cannot join AI company.");
+ IConsolePrint(CC_ERROR, "Cannot join AI company.");
return true;
}
/* Check if the company requires a password */
if (NetworkCompanyIsPassworded(company_id) && argc < 3) {
- IConsolePrintF(CC_ERROR, "Company %d requires a password to join.", company_id + 1);
+ IConsolePrint(CC_ERROR, "Company {} requires a password to join.", company_id + 1);
return true;
}
@@ -814,27 +814,27 @@ DEF_CONSOLE_CMD(ConMoveClient)
/* check the client exists */
if (ci == nullptr) {
- IConsoleError("Invalid client-id, check the command 'clients' for valid client-id's.");
+ IConsolePrint(CC_ERROR, "Invalid client-id, check the command 'clients' for valid client-id's.");
return true;
}
if (!Company::IsValidID(company_id) && company_id != COMPANY_SPECTATOR) {
- IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
+ IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
return true;
}
if (company_id != COMPANY_SPECTATOR && !Company::IsHumanID(company_id)) {
- IConsoleError("You cannot move clients to AI companies.");
+ IConsolePrint(CC_ERROR, "You cannot move clients to AI companies.");
return true;
}
if (ci->client_id == CLIENT_ID_SERVER && _network_dedicated) {
- IConsoleError("You cannot move the server!");
+ IConsolePrint(CC_ERROR, "You cannot move the server!");
return true;
}
if (ci->client_playas == company_id) {
- IConsoleError("You cannot move someone to where they already are!");
+ IConsolePrint(CC_ERROR, "You cannot move someone to where they already are!");
return true;
}
@@ -858,22 +858,22 @@ DEF_CONSOLE_CMD(ConResetCompany)
/* Check valid range */
if (!Company::IsValidID(index)) {
- IConsolePrintF(CC_ERROR, "Company does not exist. Company-id must be between 1 and %d.", MAX_COMPANIES);
+ IConsolePrint(CC_ERROR, "Company does not exist. Company-id must be between 1 and {}.", MAX_COMPANIES);
return true;
}
if (!Company::IsHumanID(index)) {
- IConsoleError("Company is owned by an AI.");
+ IConsolePrint(CC_ERROR, "Company is owned by an AI.");
return true;
}
if (NetworkCompanyHasClients(index)) {
- IConsoleError("Cannot remove company: a client is connected to that company.");
+ IConsolePrint(CC_ERROR, "Cannot remove company: a client is connected to that company.");
return false;
}
const NetworkClientInfo *ci = NetworkClientInfo::GetByClientID(CLIENT_ID_SERVER);
if (ci->client_playas == index) {
- IConsoleError("Cannot remove company: the server is connected to that company.");
+ IConsolePrint(CC_ERROR, "Cannot remove company: the server is connected to that company.");
return true;
}
@@ -957,13 +957,13 @@ DEF_CONSOLE_CMD(ConExec)
FILE *script_file = FioFOpenFile(argv[1], "r", BASE_DIR);
if (script_file == nullptr) {
- if (argc == 2 || atoi(argv[2]) != 0) IConsoleError("script file not found");
+ if (argc == 2 || atoi(argv[2]) != 0) IConsolePrint(CC_ERROR, "Script file '{}' not found.", argv[1]);
return true;
}
if (_script_current_depth == 11) {
FioFCloseFile(script_file);
- IConsoleError("Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
+ IConsolePrint(CC_ERROR, "Maximum 'exec' depth reached; script A is calling script B is calling script C ... more than 10 times.");
return true;
}
@@ -988,7 +988,7 @@ DEF_CONSOLE_CMD(ConExec)
}
if (ferror(script_file)) {
- IConsoleError("Encountered error while trying to read from script file");
+ IConsolePrint(CC_ERROR, "Encountered error while trying to read from script file '{}'.", argv[1]);
}
if (_script_current_depth == script_depth) _script_current_depth--;
@@ -1027,7 +1027,7 @@ DEF_CONSOLE_CMD(ConScript)
IConsolePrintF(CC_DEFAULT, "file output started to: %s", argv[1]);
_iconsole_output_file = fopen(argv[1], "ab");
- if (_iconsole_output_file == nullptr) IConsoleError("could not open file");
+ if (_iconsole_output_file == nullptr) IConsolePrint(CC_ERROR, "Could not open file '{}'.", argv[1]);
}
return true;
@@ -1466,7 +1466,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
if (argc > arg_index && strcmp(argv[arg_index], "no_con") == 0) {
if (type != SC_VIEWPORT) {
- IConsoleError("'no_con' can only be used in combination with 'viewport'");
+ IConsolePrint(CC_ERROR, "'no_con' can only be used in combination with 'viewport'.");
return true;
}
IConsoleClose();
@@ -1476,7 +1476,7 @@ DEF_CONSOLE_CMD(ConScreenShot)
if (argc > arg_index + 2 && strcmp(argv[arg_index], "size") == 0) {
/* size <width> <height> */
if (type != SC_DEFAULTZOOM && type != SC_ZOOMEDIN) {
- IConsoleError("'size' can only be used in combination with 'normal' or 'big'");
+ IConsolePrint(CC_ERROR, "'size' can only be used in combination with 'normal' or 'big'.");
return true;
}
GetArgumentInteger(&width, argv[arg_index + 1]);
@@ -1510,7 +1510,7 @@ DEF_CONSOLE_CMD(ConInfoCmd)
const IConsoleCmd *cmd = IConsole::CmdGet(argv[1]);
if (cmd == nullptr) {
- IConsoleError("the given command was not found");
+ IConsolePrint(CC_ERROR, "The given command was not found.");
return true;
}
@@ -1589,7 +1589,7 @@ DEF_CONSOLE_CMD(ConHelp)
return true;
}
- IConsoleError("command not found");
+ IConsolePrint(CC_ERROR, "Command not found");
return true;
}
@@ -1774,7 +1774,7 @@ DEF_CONSOLE_CMD(ConCompanyPassword)
}
if (!Company::IsValidHumanID(company_id)) {
- IConsoleError(errormsg);
+ IConsolePrint(CC_ERROR, errormsg);
return false;
}
@@ -1881,7 +1881,7 @@ DEF_CONSOLE_CMD(ConContent)
* to download every available package on BaNaNaS. This is not in
* the spirit of this service. Additionally, these few people were
* good for 70% of the consumed bandwidth of BaNaNaS. */
- IConsoleError("'select all' is no longer supported since 1.11");
+ IConsolePrint(CC_ERROR, "'select all' is no longer supported since 1.11.");
} else {
_network_content_client.Select((ContentID)atoi(argv[2]));
}
@@ -1890,7 +1890,7 @@ DEF_CONSOLE_CMD(ConContent)
if (strcasecmp(argv[1], "unselect") == 0) {
if (argc <= 2) {
- IConsoleError("You must enter the id.");
+ IConsolePrint(CC_ERROR, "You must enter the id.");
return false;
}
if (strcasecmp(argv[2], "all") == 0) {
@@ -2155,7 +2155,7 @@ DEF_CONSOLE_CMD(ConFramerateWindow)
}
if (_network_dedicated) {
- IConsoleError("Can not open frame rate window on a dedicated server");
+ IConsolePrint(CC_ERROR, "Can not open frame rate window on a dedicated server");
return false;
}
diff --git a/src/error_gui.cpp b/src/error_gui.cpp
index 06c0c44e0..d23589683 100644
--- a/src/error_gui.cpp
+++ b/src/error_gui.cpp
@@ -399,10 +399,7 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
if (textref_stack_size > 0) StopTextRefStackUsage();
- switch (wl) {
- case WL_WARNING: IConsolePrint(CC_WARNING, buf); break;
- default: IConsoleError(buf); break;
- }
+ IConsolePrint(wl == WL_WARNING ? CC_WARNING : CC_ERROR, buf);
}
bool no_timeout = wl == WL_CRITICAL;
diff --git a/src/settings.cpp b/src/settings.cpp
index a32563b53..1df7d2ac1 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1950,9 +1950,9 @@ void IConsoleSetSetting(const char *name, const char *value, bool force_newgame)
if (!success) {
if (_network_server) {
- IConsoleError("This command/variable is not available during network games.");
+ IConsolePrint(CC_ERROR, "This command/variable is not available during network games.");
} else {
- IConsoleError("This command/variable is only available to a network server.");
+ IConsolePrint(CC_ERROR, "This command/variable is only available to a network server.");
}
}
}