A base class for a structured error handling and reporting with modular architecture and fluent API.
More...
|
| FORCEINLINE decltype(InnerErrors) ::TRangedForIterator | begin () |
| |
| FORCEINLINE decltype(InnerErrors) ::TRangedForConstIterator | begin () const |
| |
| FORCEINLINE decltype(InnerErrors) ::TRangedForIterator | end () |
| |
| FORCEINLINE decltype(InnerErrors) ::TRangedForConstIterator | end () const |
| |
| void | Initialize () |
| | This is an empty function so any IError can fulfill CSharedInitializeable without needing extra attention in derived classes. Simply hide this function with overloads in derived classes if they need to use TSharedFromThis for initialization.
|
| |
| virtual void | SerializeYaml (YAML::Emitter &emitter) const |
| | Override this function to change the method how this error is entirely serialized into a YAML format.
|
| |
| FString | ToString () const |
| | Render this error as a string using the YAML representation.
|
| |
| std::string | ToStringUtf8 () const |
| | Render this error as a std::string using the YAML representation.
|
| |
| FORCEINLINE EErrorSeverity | GetSeverity () const |
| |
| FORCEINLINE int32 | GetSeverityInt () const |
| |
| FORCEINLINE FString const & | GetMessage () const |
| |
| FORCEINLINE FString const & | GetDetails () const |
| |
| FORCEINLINE FString const & | GetCodeContext () const |
| |
| FORCEINLINE TMap< FString, IErrorRef > const & | GetInnerErrors () const |
| |
| FORCEINLINE int32 | GetInnerErrorCount () const |
| |
| TArray< FString > | GetErrorPropagation () const |
| | Get a list of source locations where this error has been handled. This is not equivalent of stack-traces but rather a historical record of where this error was considered throughout the source code. Each item in this list is explicitly recorded via WithLocation. The first item is the earliest consideration of this error.
|
| |
| FString | GetErrorPropagationJoined () const |
| | Same as GetErrorPropagation but items are separated by new line.
|
| |
| FStringView | GetSeverityString () const |
| | Get the error severity as an unreal string.
|
| |
| virtual TSharedRef< SErrorDisplay > | CreateErrorWidget () |
| | Override this function to customize how an error is displaxed for the end-user.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithMessage (this Self &&self, const FString &input, bool condition=true) |
| | Specify error message with a fluent API.
|
| |
| template<typename Self , CStringFormatArgument... FormatArgs> |
| SelfRef< Self > | WithMessageF (this Self &&self, const TCHAR *input, FormatArgs &&... fmtArgs) |
| | Specify formatted error message with a fluent API.
|
| |
| template<typename Self , typename... FormatArgs> |
| SelfRef< Self > | WithMessageFC (this Self &&self, bool condition, const TCHAR *input, FormatArgs &&... fmtArgs) |
| | Specify formatted error message with a fluent API.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithSeverity (this Self &&self, EErrorSeverity input) |
| | Specify severity with a fluent API.
|
| |
| template<typename Self > |
| SelfRef< Self > | AsRecoverable (this Self &&self) |
| | Recoverable shorthand.
|
| |
| template<typename Self > |
| SelfRef< Self > | AsFatal (this Self &&self) |
| | Fatal shorthand.
|
| |
| template<typename Self > |
| SelfRef< Self > | AsCrashing (this Self &&self) |
| | Crashing shorthand.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithDetails (this Self &&self, const FString &input, bool condition=true) |
| | Specify details for the error which may provide further context for the user or provide them reminders/suggestions.
|
| |
| template<typename Self , CStringFormatArgument... FormatArgs> |
| SelfRef< Self > | WithDetailsF (this Self &&self, const TCHAR *input, FormatArgs &&... fmtArgs) |
| | Specify formatted details for the error which may provide further context for the user or provide them reminders/suggestions.
|
| |
| template<typename Self , CStringFormatArgument... FormatArgs> |
| SelfRef< Self > | WithDetailsFC (this Self &&self, bool condition, const TCHAR *input, FormatArgs &&... fmtArgs) |
| | Specify formatted details for the error which may provide further context for the user or provide them reminders/suggestions.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithCodeContext (this Self &&self, const FString &input, bool condition=true) |
| | If available write a source code context into the error directly displaying where this error has occured.
|
| |
| template<typename Self , CError Error> |
| SelfRef< Self > | WithError (this Self &&self, const TSharedRef< Error > &input, bool condition=true) |
| | Add a uniquely typed inner error.
|
| |
| template<typename Self , CError Error> |
| SelfRef< Self > | WithError (this Self &&self, const FString &name, const TSharedRef< Error > &input, bool condition=true) |
| | Add one inner error with specific name.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithErrors (this Self &&self, const TArray< TTuple< FString, IErrorRef > > &input, bool condition=true) |
| | Add multiple errors at once with optional names.
|
| |
| template<typename Self , CError... Errors> |
| SelfRef< Self > | WithErrors (this Self &&self, const TSharedRef< Errors > &... errors) |
| | Add multiple errors at once.
|
| |
| template<typename Self , CError... Errors> |
| SelfRef< Self > | WithErrors (this Self &&self, bool condition, const TSharedRef< Errors > &... errors) |
| | Add multiple errors at once.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithAppendix (this Self &&self, const FString &name, const FString &text, bool condition=true) |
| | Add an extra plain text block inside inner errors.
|
| |
| template<typename Self , CStringFormatArgument... FormatArgs> |
| SelfRef< Self > | WithAppendixF (this Self &&self, const FString &name, const TCHAR *text, FormatArgs &&... fmtArgs) |
| | Add an extra plain text block inside inner errors.
|
| |
| template<typename Self , CStringFormatArgument... FormatArgs> |
| SelfRef< Self > | WithAppendixFC (this Self &&self, bool condition, const FString &name, const TCHAR *text, FormatArgs &&... fmtArgs) |
| | Add an extra plain text block inside inner errors.
|
| |
| template<typename Self > |
| SelfRef< Self > | Notify (this Self &&self, Observable::IState< IErrorPtr > &state) |
| | Notify an observable state about this error.
|
| |
| template<typename Self > |
| SelfRef< Self > | BreakDebugger (this Self &&self) |
| | Break if a debugger is attached when this error is created.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithCppStackTrace (this Self &&self, const FString &name={}, bool condition=true, int32 numAdditionalStackFramesToIgnore=0, bool fastWalk=!UE_BUILD_DEBUG) |
| | Shorthand for adding the current C++ stacktrace to this error.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithBlueprintStackTrace (this Self &&self, const FString &name={}, bool condition=true) |
| | Shorthand for adding the current Blueprint stacktrace to this error.
|
| |
| template<typename Self > |
| SelfRef< Self > | WithLocation (this Self &&self, std::source_location const &location=std::source_location::current()) |
| | Allow the error to record the source locations it has been handled at compile time. For example this gives more information than stack-traces because it can also record where errors were handled between parallel threads.
|
| |
| template<typename Self > |
| SelfRef< Self > | Report (this Self &&self, bool condition=true) |
| | Report this error to the global IError::OnErrorReported event once it is deemed "ready", so an issue tracking system can handle important error unintrusively. Make sure this is the last modification on the error. Only call it once no further information can be added and on the top-most main error in case of aggregate errors.
|
| |
| template<typename Self , CFunctionCompatible_ArgumentsDecay< void(SelfRef< Self >)> Function> |
| SelfRef< Self > | AsOperandWith (this Self &&self, Function &&function) |
| | Call an arbitrary function with this error. Other than cases like invoking macros inline operating on errors (like the inline ERROR_LOG overload) this may have limited use.
|
| |
| virtual | ~IHaveType ()=default |
| |
| template<CSharedFromThis Self> |
| SelfRef< Self > | WithType (this Self &&self) |
| | Fluent API for setting tpye for deferred initialization (for example in factory functions)
|
| |
template<typename Self >
requires (!CSharedFromThis<Self>) |
| Self && | WithType (this Self &&self) |
| | Fluent API for setting tpye for deferred initialization (for example in factory functions)
|
| |
| FORCEINLINE FType const & | GetType () const |
| |
| FORCEINLINE FName const & | GetTypeFName () const |
| |
| FORCEINLINE FString | GetTypeString () const |
| |
| template<typename Derived , CSharedFromThis Self> |
| TSharedPtr< Derived > | As (this Self &&self) |
| | Dynamic casting of this object to a derived top-level type. Casting also works if inheritance is done through TInherit template.
|
| |
template<typename Derived , typename Self >
requires (!CSharedFromThis<Self>) |
| Derived * | As (this Self &&self) |
| | Dynamic casting of this object to a derived top-level type. Casting also works if inheritance is done through TInherit template.
|
| |
A base class for a structured error handling and reporting with modular architecture and fluent API.
- Important
- Instantiate errors only with
IError::Make(new FMyError()) this ensures the minimal runtime reflection features.
Many times runtime errors are unavoidable and if an API only gives indication of success or failure (let's say in the form of a boolean) that will be quite frustrating for the user to report, as it gives no direction of course what went wrong, how it went wrong, and when it went wrong. Slightly better when the API gives a list of things what can go wrong and return an item from that list when things go wrong. This of course still doesn't allow to provide much of a context for the user.
An 'improvement' to that is using C++ exceptions, however it is not unanimously well received in the community because it can hide the fact that the API can bail on its caller. So when exceptions are enabled one may call every function of an API like if they were walking on a minefield. For this (and a couple more) reasons C++ exceptions are disabled by default in Unreal projects and viewed as terrible practice to introduce it ourselves.
Unreal does provide though the TValueOrError template which allows API's to indicate that they can fail in some ways without the need to consult an external documentation. It gives the developer total freedom however of what the error can be, so on its own it does not solve the questions of what/when/how.
Using TMaybe with IError can be a powerful tool in the developer's arsenal when creating a library. IError can standardize a detailed and structured way of communicating errors without hindering call-site usage. It can also automate the method and the format of logging the (many times excessive amount of) information surrounding an error, or decide how it may be presented for the user.
Definition at line 67 of file Error.h.