MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
Error.h File Reference
#include "CoreMinimal.h"
#include "Templates/ValueOrError.h"
#include "Mcro/Error.Fwd.h"
#include "Void.h"
#include "Mcro/Types.h"
#include "Mcro/Concepts.h"
#include "Mcro/SharedObjects.h"
#include "Mcro/Observable.Fwd.h"
#include "Mcro/TextMacros.h"
#include "Mcro/Text.h"
#include "Mcro/Delegates/EventDelegate.h"
#include "Mcro/LibraryIncludes/Start.h"
#include "yaml-cpp/yaml.h"
#include "Mcro/LibraryIncludes/End.h"
#include <source_location>

Go to the source code of this file.

Data Structures

class  Mcro::Error::IError
 A base class for a structured error handling and reporting with modular architecture and fluent API. More...
 
class  Mcro::Error::FAssertion
 A simple error type for checking booleans. It adds no extra features to IError. More...
 
class  Mcro::Error::FUnavailable
 A simple error type denoting that whatever is being accessed is not available like attempting to access nullptr. It adds no extra features to IError. More...
 
struct  Mcro::Error::TMaybe< T >
 A TValueOrError alternative for IError which allows implicit conversion from values and errors (no need for MakeError or MakeValue) and is boolean testable. It also doesn't have ambiguous state such as TValueOrError has, so a TMaybe will always have either an error or a value, it will never have neither of them or both of them. More...
 

Namespaces

namespace  Mcro
 
namespace  Mcro::Error
 Contains utilities for structured error handling.
 

Macros

#define MCRO_ERROR_LOG_3(categoryName, verbosity, error)
 
#define MCRO_ERROR_LOG_2(categoryName, verbosity)
 
#define ERROR_LOG(...)
 Convenience macro for logging an error with UE_LOG.
 
#define ERROR_CLOG(condition, categoryName, verbosity, error)
 
#define MCRO_ASSERT_RETURN_2(condition, error)
 
#define MCRO_ASSERT_RETURN_1(condition)
 
#define ASSERT_RETURN(...)
 Similar to check() macro, but return an error instead of crashing.
 
#define MCRO_UNAVAILABLE_1(error)
 
#define UNAVAILABLE(error)
 Denote that a resource which is asked for doesn't exist.
 
#define MCRO_PROPAGATE_FAIL_3(type, var, expression)
 
#define MCRO_PROPAGATE_FAIL_2(var, expression)
 
#define MCRO_PROPAGATE_FAIL_1(expression)
 
#define PROPAGATE_FAIL(...)
 If a function returns a TMaybe or an FCanFail inside another function which may also return another error use this convenience macro to propagate the failure.
 

Typedefs

using Mcro::Error::FCanFail = TMaybe<FVoid>
 Indicate that an otherwise void function that it may fail with an IError.
 
using Mcro::Error::FTrueOrReason = TMaybe<FVoid>
 Syntactically same as FCanFail but for functions which is explicitly used to query some boolean decidable thing, and which can also provide a reason why the queried thing is false.
 

Functions

FORCEINLINE FCanFail Mcro::Error::Success ()
 Return an FCanFail or FTrueOrReason indicating a success or truthy output.
 

Detailed Description

Author
David Mórász
Date
2025

Definition in file Error.h.

Macro Definition Documentation

◆ ASSERT_RETURN

#define ASSERT_RETURN ( ...)
Value:
MACRO_OVERLOAD(MCRO_ASSERT_RETURN_, __VA_ARGS__)
#define MACRO_OVERLOAD(prefix,...)
Implement preprocessor function overloading based on argument count for a set of macros following a d...
Definition Macros.h:71

Similar to check() macro, but return an error instead of crashing.

The following overloads are available:

  • (condition, error) Specify error type to return
  • (condition) Return FAssertion error

Definition at line 735 of file Error.h.

◆ ERROR_CLOG

#define ERROR_CLOG ( condition,
categoryName,
verbosity,
error )
Value:
UE_CLOG(condition, categoryName, verbosity, TEXT_"%s", *((error) \
->WithLocation() \
->Report() \
->ToString() \
))
#define TEXT_
A convenience alternative to Unreal's own TEXT macro but this one doesn't require parenthesis around ...
Definition TextMacros.h:53

Definition at line 712 of file Error.h.

◆ ERROR_LOG

#define ERROR_LOG ( ...)
Value:
MACRO_OVERLOAD(MCRO_ERROR_LOG_, __VA_ARGS__)

Convenience macro for logging an error with UE_LOG.

The following overloads are available:

  • (categoryName, verbosity, error) Simply use UE_LOG to log the error
  • (categoryName, verbosity) Log the error preceding this macro (use ERROR_LOG inline). WithLocation is omitted from this overload

Definition at line 710 of file Error.h.

◆ MCRO_ASSERT_RETURN_1

#define MCRO_ASSERT_RETURN_1 ( condition)
Value:
#define MCRO_ASSERT_RETURN_2(condition, error)
Definition Error.h:719
A simple error type for checking booleans. It adds no extra features to IError.
Definition Error.h:568

Definition at line 726 of file Error.h.

◆ MCRO_ASSERT_RETURN_2

#define MCRO_ASSERT_RETURN_2 ( condition,
error )
Value:
if (UNLIKELY(!(condition))) \
return Mcro::Error::IError::Make(new error) \
->WithLocation() \
->AsRecoverable() \
->WithCodeContext(PREPROCESSOR_TO_TEXT(condition))
#define PREPROCESSOR_TO_TEXT(x)
Definition Macros.h:51
static TSharedRef< T > Make(T *newError, Args &&... args)
To ensure automatic type reflection use IError::Make instead of manually constructing error objects.
Definition Error.h:148

Definition at line 719 of file Error.h.

◆ MCRO_ERROR_LOG_2

#define MCRO_ERROR_LOG_2 ( categoryName,
verbosity )
Value:
Report() \
->AsOperandWith([](IErrorRef const& error) \
{ \
UE_LOG(categoryName, verbosity, TEXT_"%s", *(error->ToString())); \
})

Definition at line 695 of file Error.h.

◆ MCRO_ERROR_LOG_3

#define MCRO_ERROR_LOG_3 ( categoryName,
verbosity,
error )
Value:
UE_LOG(categoryName, verbosity, TEXT_"%s", *((error) \
->WithLocation() \
->Report() \
->ToString() \
))

Definition at line 688 of file Error.h.

◆ MCRO_PROPAGATE_FAIL_1

#define MCRO_PROPAGATE_FAIL_1 ( expression)
Value:
MCRO_PROPAGATE_FAIL_2(PREPROCESSOR_JOIN(tempResult, __LINE__), expression)
#define MCRO_PROPAGATE_FAIL_2(var, expression)
Definition Error.h:756

Definition at line 757 of file Error.h.

◆ MCRO_PROPAGATE_FAIL_2

#define MCRO_PROPAGATE_FAIL_2 ( var,
expression )
Value:
MCRO_PROPAGATE_FAIL_3(auto, var, expression)
#define MCRO_PROPAGATE_FAIL_3(type, var, expression)
Definition Error.h:751

Definition at line 756 of file Error.h.

◆ MCRO_PROPAGATE_FAIL_3

#define MCRO_PROPAGATE_FAIL_3 ( type,
var,
expression )
Value:
type var = (expression); \
if (UNLIKELY(var.HasError())) return var.GetError() \
->WithLocation()

Definition at line 751 of file Error.h.

◆ MCRO_UNAVAILABLE_1

#define MCRO_UNAVAILABLE_1 ( error)
Value:
->WithLocation() \
->AsRecoverable()
#define DEFAULT_ON_EMPTY(value, default)
Returns given default value when input value is empty.
Definition Macros.h:74
A simple error type denoting that whatever is being accessed is not available like attempting to acce...
Definition Error.h:576

Definition at line 737 of file Error.h.

◆ PROPAGATE_FAIL

#define PROPAGATE_FAIL ( ...)
Value:
MACRO_OVERLOAD(MCRO_PROPAGATE_FAIL_, __VA_ARGS__)

If a function returns a TMaybe or an FCanFail inside another function which may also return another error use this convenience macro to propagate the failure.

The following overloads are available:

  • (expression) Use this when the value of success is not needed further below. This will create a local variable with an automatically determined name and type
  • (var, expression) Use this when the value of success will be used further below. The local variable will be created with auto
  • (type, var, expression) Use this when the value of success will be used further below and its local variable should have an explicit type

Definition at line 772 of file Error.h.

◆ UNAVAILABLE

#define UNAVAILABLE ( error)
Value:
#define MCRO_UNAVAILABLE_1(error)
Definition Error.h:737

Denote that a resource which is asked for doesn't exist.

The following overloads are available:

  • (error) Specify error type to return
  • () Return FUnavailable error

Definition at line 749 of file Error.h.