OpenTTD Source 20250312-master-gcdcc6b491d
error.h File Reference

Functions related to errors. More...

#include "strings_type.h"
#include "company_type.h"
#include "command_type.h"
#include "core/geometry_type.hpp"
#include <chrono>

Go to the source code of this file.

Data Structures

class  ErrorMessageData
 The data of the error message. More...
 

Typedefs

typedef std::list< ErrorMessageDataErrorList
 Define a queue with errors.
 

Enumerations

enum  WarningLevel : uint8_t { WL_INFO , WL_WARNING , WL_ERROR , WL_CRITICAL }
 Message severity/type. More...
 

Functions

void ScheduleErrorMessage (ErrorList &datas)
 Schedule a list of errors.
 
void ScheduleErrorMessage (const ErrorMessageData &data)
 Schedule an error.
 
void ShowErrorMessage (EncodedString &&summary_msg, int x, int y, const CommandCost &cc)
 Display an error message in a window.
 
void ShowErrorMessage (EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel wl, int x=0, int y=0, EncodedString &&extra_msg={}, CompanyID company=CompanyID::Invalid())
 Display an error message in a window.
 
bool HideActiveErrorMessage ()
 Close active error message window.
 
void ClearErrorMessages ()
 Clear all errors from the queue.
 
void ShowFirstError ()
 Show the first error of the queue.
 
void UnshowCriticalError ()
 Unshow the critical error.
 

Detailed Description

Functions related to errors.

Definition in file error.h.

Typedef Documentation

◆ ErrorList

typedef std::list<ErrorMessageData> ErrorList

Define a queue with errors.

Definition at line 48 of file error.h.

Enumeration Type Documentation

◆ WarningLevel

enum WarningLevel : uint8_t

Message severity/type.

Enumerator
WL_INFO 

Used for DoCommand-like (and some non-fatal AI GUI) errors/information.

WL_WARNING 

Other information.

WL_ERROR 

Errors (eg. saving/loading failed)

WL_CRITICAL 

Critical errors, the MessageBox is shown in all cases.

Definition at line 23 of file error.h.

Function Documentation

◆ ClearErrorMessages()

void ClearErrorMessages ( )

Clear all errors from the queue.

Definition at line 251 of file error_gui.cpp.

References UnshowCriticalError().

Referenced by SaveLoadWindow::OnClick(), and ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE().

◆ HideActiveErrorMessage()

bool HideActiveErrorMessage ( )

Close active error message window.

Returns
true if a window was closed.

Definition at line 355 of file error_gui.cpp.

References ErrmsgWindow::Close(), FindWindowById(), and WC_ERRMSG.

Referenced by MainWindow::OnHotkey().

◆ ScheduleErrorMessage() [1/2]

void ScheduleErrorMessage ( const ErrorMessageData data)

Schedule an error.

Note: This does not try to display the error now. This is useful if the window system is not yet running.

Parameters
dataError message data; cleared afterwards

Definition at line 378 of file error_gui.cpp.

References _error_list.

◆ ScheduleErrorMessage() [2/2]

void ScheduleErrorMessage ( ErrorList datas)

Schedule a list of errors.

Note: This does not try to display the error now. This is useful if the window system is not yet running.

Parameters
datasError message datas; cleared afterwards

Definition at line 368 of file error_gui.cpp.

References _error_list.

Referenced by LoadFromConfig(), openttd_main(), and DriverFactoryBase::SelectDriverImpl().

◆ ShowErrorMessage() [1/2]

void ShowErrorMessage ( EncodedString &&  summary_msg,
EncodedString &&  detailed_msg,
WarningLevel  wl,
int  x,
int  y,
EncodedString &&  extra_msg,
CompanyID  company 
)

Display an error message in a window.

Parameters
summary_msgGeneral error message showed in first line. Must be valid.
detailed_msgDetailed error message showed in second line. Can be empty.
wlMessage severity.
xWorld X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
yWorld Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
extra_msgExtra error message shown in third line. Can be empty.

Definition at line 308 of file error_gui.cpp.

References _error_list, _settings_client, CC_ERROR, CC_WARNING, ErrmsgWindow::Close(), GUISettings::errmsg_duration, FindWindowById(), ClientSettings::gui, IConsolePrint(), ErrmsgWindow::IsCritical(), WC_ERRMSG, WL_CRITICAL, WL_INFO, and WL_WARNING.

◆ ShowErrorMessage() [2/2]

void ShowErrorMessage ( EncodedString &&  summary_msg,
int  x,
int  y,
const CommandCost cc 
)

Display an error message in a window.

Note: CommandCost errors are always severity level WL_INFO.

Parameters
summary_msgGeneral error message showed in first line. Must be valid.
xWorld X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
yWorld Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
ccCommandCost containing the optional detailed and extra error messages shown in the second and third lines (can be empty).

Definition at line 290 of file error_gui.cpp.

References CommandCost::GetEncodedMessage(), GetEncodedStringIfValid(), CommandCost::GetErrorMessage(), CommandCost::GetErrorOwner(), CommandCost::GetExtraErrorMessage(), ShowErrorMessage(), and WL_INFO.

Referenced by NewGRFWindow::AddGRFToActive(), ClientNetworkContentSocketHandler::AfterDownload(), AfterLoadGame(), ClientNetworkContentSocketHandler::BeforeDownload(), CcBuildIndustry(), ClientNetworkGameSocketHandler::CheckConnection(), CheckDynamicEngines(), CheckEngines(), CheckForMissingGlyphs(), CheckIndustries(), CheckTownRoadTypes(), CheckTrainsLengths(), ClickChangeMaxHlCheat(), NetworkGameSocketHandler::CloseConnection(), CmdBuildIndustry(), AIInstance::Died(), GameInstance::Died(), DoAutoOrNetsave(), ErrorUnknownCallbackResult(), GenerateTowns(), GetOrderCmdFromTile(), GetSavegameFormat(), GraphicsSetLoadConfig(), GRFLoadConfig(), IndustryProductionCallback(), CommandHelperBase::InternalPostBefore(), CommandHelperBase::InternalPostResult(), LoadTownData(), NetworkValidateClientName(), NetworkValidateServerName(), AIConfigWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), SaveLoadWindow::OnClick(), GSConfigWindow::OnClick(), SelectGameWindow::OnClick(), NewGRFWindow::OnClick(), GameOptionsWindow::OnClick(), FoundTownWindow::OnClick(), NetworkContentListWindow::OnConnect(), GameOptionsWindow::OnDropdownSelect(), BuildIndustryWindow::OnPlaceObject(), SelectCompanyManagerFaceWindow::OnQueryTextFinished(), SaveLoadWindow::OnTimeout(), DepotWindow::OnVehicleSelect(), OrdersWindow::OnVehicleSelect(), ReadHeightmapBMP(), ReadHeightmapPNG(), RealMakeScreenshot(), ClientNetworkCoordinatorSocketHandler::Receive_GC_ERROR(), ClientNetworkCoordinatorSocketHandler::Receive_GC_REGISTER_ACK(), ClientNetworkGameSocketHandler::Receive_SERVER_BANNED(), ClientNetworkGameSocketHandler::Receive_SERVER_CHECK_NEWGRFS(), ClientNetworkContentSocketHandler::Receive_SERVER_CONTENT(), ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(), ClientNetworkGameSocketHandler::Receive_SERVER_FULL(), ClientNetworkGameSocketHandler::Receive_SERVER_MAP_DONE(), ClientNetworkGameSocketHandler::Receive_SERVER_NEWGAME(), ClientNetworkGameSocketHandler::Receive_SERVER_SHUTDOWN(), SaveFileError(), SaveOrLoad(), ShowBuildBridgeWindow(), ShowErrorMessage(), ShowEstimatedCostOrIncome(), ShowNetworkContentListWindow(), ShowNewGRFError(), ShowNewGrfVehicleError(), ShowScriptDebugWindow(), TownActionBribe(), and WarnCorruptSprite().

◆ ShowFirstError()

void ShowFirstError ( )

Show the first error of the queue.

Definition at line 258 of file error_gui.cpp.

References _error_list, and _window_system_initialized.

Referenced by CleanupGeneration(), ErrmsgWindow::Close(), InitWindowSystem(), and LoadFromConfig().

◆ UnshowCriticalError()

void UnshowCriticalError ( )

Unshow the critical error.

This has to happen when a critical error is shown and we uninitialise the window system, i.e. remove all the windows.

Definition at line 272 of file error_gui.cpp.

References _error_list, _window_system_initialized, ErrmsgWindow::Close(), FindWindowById(), ErrmsgWindow::IsCritical(), and WC_ERRMSG.

Referenced by ClearErrorMessages(), GenerateWorld(), and UnInitWindowSystem().