MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
ErrorManager.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13
14#include "CoreMinimal.h"
15#include "HAL/ThreadSafeBool.h"
16#include "Widgets/SWidget.h"
17#include "Widgets/SWindow.h"
18#include "Mcro/Error.h"
21
22namespace Mcro::Error
23{
24 using namespace Mcro::AutoModularFeature;
25
26 /** @brief Control how an error is being displayed. Use C++ 20 designated initializers for convenience */
28 {
29 /**
30 * @brief
31 * The error message will not block the engine tick. This is useful for errors happening in the editor
32 * so even if PIE session is aborted due to an error, the developer can cross-check their assets with the
33 * error still open.
34 */
35 bool bAsync = false;
36
37 /** @brief Enables an extra checkbox which reminds the user to please do not immediately dismiss the error */
38 bool bImportantToRead = false;
39
40 /**
41 * @brief
42 * Set this to false if for any reason you don't need the debugger to break before displaying the error
43 * to the user.
44 */
45 bool bBreakDebugger = true;
46
47 /**
48 * @brief
49 * Set this to false if for any reason you don't need the error to be logged before displaying it to the user.
50 */
51 bool bLogError = true;
52
53 /**
54 * @brief
55 * Optionally set a parent widget for the modal window of the error. By default if not specified here the
56 * main editor window is used, or the main gameplay viewport.
57 */
58 TSharedPtr<const SWidget> Parent = {};
59 };
60
61 /**
62 * @brief
63 * A modular feature which allows other modules to inject their own UI into error windows displayed to the user.
64 */
65 class MCRO_API IErrorWindowExtension : public TAutoModularFeature<IErrorWindowExtension>
66 {
67 public:
68 virtual bool SupportsError(IErrorRef const& error, FDisplayErrorArgs const& displayArgs) { return true; };
69 virtual TSharedPtr<SWidget> PreErrorDisplay(IErrorRef const& error, FDisplayErrorArgs const& displayArgs) { return {}; };
70 virtual TSharedPtr<SWidget> PostErrorDisplay(IErrorRef const& error, FDisplayErrorArgs const& displayArgs) { return {}; };
71 };
72
73 /** @brief Global facilities for IError handling, including displaying them to the user, trigger error events, etc */
74 class MCRO_API FErrorManager
75 {
76 public:
77
78 /** @brief Get the global singleton */
79 static FErrorManager& Get();
80
81 /** @brief The results of displaying an error. In all cases the error is logged. */
83 {
84 /** @brief The error has been displayed for the user. */
86
87 /** @brief The error has not been shown to the user because another error is already being shown. */
89
90 /** @brief Modal windows couldn't be created at the time, so we couldn't show it to the user either. */
92 };
93
94 /**
95 * @brief
96 * Display the error summary for the user. Only use this when your program arrives to an unrecoverable state
97 * which either needs explanation for the user or requires action from the user (like configuration changes).
98 *
99 * @important
100 * The modal window and the widgets representing the error will be created on the main thread, keep that in
101 * mind while making the widgets for the errors.
102 *
103 * @param error The input error
104 * @param args Simple arguments object for this function, use initializer list or C++ 20 designated initializer.
105 *
106 * @return
107 * A future telling that either the dialog has been displayed or how it has been suppressed. The future also
108 * gives an opportunity to block the calling thread until the user acknowledges the error.
109 *
110 * @remarks
111 * Unless `bAsync` is set in the arguments, calling this function from any thread will also block the main
112 * thread while the modal window containing the error is open. If the calling thread also needs to be blocked
113 * then simply wait on the returned future.
114 *
115 * @todo
116 * Add ability to let the user "ignore" errors, and continue execution, because they know better.
117 */
118 auto DisplayError(IErrorRef const& error, FDisplayErrorArgs const& args) -> TFuture<EDisplayErrorResult>;
119
121
122 private:
123
124 auto DisplayError_MainThread(IErrorRef const& error, FDisplayErrorArgs const& args) -> EDisplayErrorResult;
125 auto InferParentWidget() -> TSharedPtr<const SWidget>;
126
127 TSharedPtr<SWindow> ModalWindow;
128 FThreadSafeBool bIsDisplayingError;
129 };
130}
Auto Modular Features are a workflow with Modular Features where the developer doesn't have to rely o...
"Extension" of a common TMulticastDelegate. It allows to define optional "flags" when adding a bindin...
Global facilities for IError handling, including displaying them to the user, trigger error events,...
static FErrorManager & Get()
Get the global singleton.
EDisplayErrorResult
The results of displaying an error. In all cases the error is logged.
@ Displayed
The error has been displayed for the user.
@ Suppressed_AnotherErrorOpen
The error has not been shown to the user because another error is already being shown.
@ Suppressed_CannotDisplayModalWindow
Modal windows couldn't be created at the time, so we couldn't show it to the user either.
TEventDelegate< void()> OnErrorDialogDismissed
auto DisplayError(IErrorRef const &error, FDisplayErrorArgs const &args) -> TFuture< EDisplayErrorResult >
Display the error summary for the user. Only use this when your program arrives to an unrecoverable s...
A modular feature which allows other modules to inject their own UI into error windows displayed to t...
virtual TSharedPtr< SWidget > PreErrorDisplay(IErrorRef const &error, FDisplayErrorArgs const &displayArgs)
virtual bool SupportsError(IErrorRef const &error, FDisplayErrorArgs const &displayArgs)
virtual TSharedPtr< SWidget > PostErrorDisplay(IErrorRef const &error, FDisplayErrorArgs const &displayArgs)
Contains utilities for structured error handling.
Definition Error.Fwd.h:19
TSharedRef< IError > IErrorRef
Convenience alias for an instance of an error.
Definition Error.Fwd.h:25
Control how an error is being displayed. Use C++ 20 designated initializers for convenience.
TSharedPtr< const SWidget > Parent
Optionally set a parent widget for the modal window of the error. By default if not specified here th...
bool bLogError
Set this to false if for any reason you don't need the error to be logged before displaying it to the...
bool bAsync
The error message will not block the engine tick. This is useful for errors happening in the editor s...
bool bBreakDebugger
Set this to false if for any reason you don't need the debugger to break before displaying the error ...
bool bImportantToRead
Enables an extra checkbox which reminds the user to please do not immediately dismiss the error.