14#include "CoreMinimal.h"
23#include "yaml-cpp/yaml.h"
26#include <source_location>
80 virtual void AddError(
const FString& name,
const TSharedRef<IError>& error,
const FString& typeOverride = {});
83 virtual void AddAppendix(
const FString& name,
const FString& text,
const FString& type = TEXT(
"Appendix"));
85 void AddCppStackTrace(
const FString& name, int32 numAdditionalStackFramesToIgnore,
bool fastWalk);
98 FORCEINLINE
decltype(InnerErrors)::TRangedForIterator
begin() {
return InnerErrors.begin(); }
99 FORCEINLINE
decltype(InnerErrors)::TRangedForConstIterator
begin()
const {
return InnerErrors.begin(); }
100 FORCEINLINE
decltype(InnerErrors)::TRangedForIterator
end() {
return InnerErrors.end(); }
101 FORCEINLINE
decltype(InnerErrors)::TRangedForConstIterator
end()
const {
return InnerErrors.end(); }
134 template <
CError T,
typename... Args>
135 requires CSharedInitializeable<T, Args...>
136 static TSharedRef<T>
Make(T* newError, Args&&... args)
142 FORCEINLINE int32
GetSeverityInt()
const {
return static_cast<int32
>(Severity); }
143 FORCEINLINE FString
const&
GetMessage()
const {
return Message; }
144 FORCEINLINE FString
const&
GetDetails()
const {
return Details; }
146 FORCEINLINE TMap<FString, IErrorRef>
const&
GetInnerErrors()
const {
return InnerErrors; }
173 template <
typename Self>
176 if (condition) self.Message = input;
177 return self.SharedThis(&self);
188 template <
typename Self,
typename... FormatArgs>
191 self.Message =
DynamicPrintf(input, Forward<FormatArgs>(fmtArgs)...);
192 return self.SharedThis(&self);
204 template <
typename Self,
typename... FormatArgs>
207 if (condition) self.Message =
DynamicPrintf(input, Forward<FormatArgs>(fmtArgs)...);
208 return self.SharedThis(&self);
219 template <
typename Self>
222 self.Severity = input;
223 return self.SharedThis(&self);
227 template <
typename Self>
230 self.Severity = EErrorSeverity::Recoverable;
231 return self.SharedThis(&self);
235 template <
typename Self>
238 self.Severity = EErrorSeverity::Fatal;
239 return self.SharedThis(&self);
243 template <
typename Self>
246 self.Severity = EErrorSeverity::Crashing;
247 return self.SharedThis(&self);
259 template <
typename Self>
262 if (condition) self.Details = input;
263 return self.SharedThis(&self);
275 template <
typename Self,
typename... FormatArgs>
278 self.Details =
DynamicPrintf(input, Forward<FormatArgs>(fmtArgs)...);
279 return self.SharedThis(&self);
292 template <
typename Self,
typename... FormatArgs>
295 if (condition) self.Details =
DynamicPrintf(input, Forward<FormatArgs>(fmtArgs)...);
296 return self.SharedThis(&self);
307 template <
typename Self>
310 if (condition) self.CodeContext = input;
311 return self.SharedThis(&self);
323 template <
typename Self, CError Error>
326 if (condition) self.AddError({}, input);
327 return self.SharedThis(&self);
340 template <
typename Self, CError Error>
343 if (condition) self.AddError(name, input);
344 return self.SharedThis(&self);
354 template <
typename Self>
359 for (
const auto& error : input)
360 self.AddError(error.Key, error.Value);
362 return self.SharedThis(&self);
372 template <
typename Self,
CError... Errors>
375 (self.AddError({}, errors), ...);
376 return self.SharedThis(&self);
387 template <
typename Self,
CError... Errors>
390 if (condition) self.WithErrors(errors...);
391 return self.SharedThis(&self);
402 template <
typename Self>
405 if (condition) self.AddAppendix(name, text);
406 return self.SharedThis(&self);
417 template <
typename Self,
typename... FormatArgs>
420 self.AddAppendix(name,
DynamicPrintf(text, Forward<FormatArgs>(fmtArgs)...));
421 return self.SharedThis(&self);
433 template <
typename Self,
typename... FormatArgs>
437 self.AddAppendix(name,
DynamicPrintf(text, Forward<FormatArgs>(fmtArgs)...));
438 return self.SharedThis(&self);
442 template <
typename Self>
445 self.NotifyState(state);
446 return self.SharedThis(&self);
450 template <
typename Self>
454 return self.SharedThis(&self);
458 template <
typename Self>
459 SelfRef<Self> WithCppStackTrace(
this Self&& self,
const FString& name = {},
bool condition =
true, int32 numAdditionalStackFramesToIgnore = 0,
bool fastWalk = !UE_BUILD_DEBUG)
461#if !UE_BUILD_SHIPPING
463 self.AddCppStackTrace(name, numAdditionalStackFramesToIgnore + 1, fastWalk);
465 return self.SharedThis(&self);
469 template <
typename Self>
472#if !UE_BUILD_SHIPPING
474 self.AddBlueprintStackTrace(name);
476 return self.SharedThis(&self);
487 template <
typename Self>
490 self.ErrorPropagation.Add(location);
491 return self.SharedThis(&self);
513 template <CNonVo
id T>
522 template <
typename = T>
523 requires (!CDefaultInitializable<T>)
526 TEXT(
"TMaybe has been default initialized, but a Value of %s cannot be default initialized"),
532 template <CDefaultInitializable = T>
536 template <CConvertibleToDecayed<T> From, CCopyConstructible = T>
537 TMaybe(From
const& value) : Value(value) {}
540 template <CConvertibleToDecayed<T> From, CMoveConstructible = T>
541 TMaybe(From&& value) : Value(Forward<From>(value)) {}
544 template <CConvertibleToDecayed<T> From, CCopyConstructible = T>
548 template <CConvertibleToDecayed<T> From, CMoveConstructible = T>
552 template <CError ErrorType>
553 TMaybe(TSharedRef<ErrorType>
const& error) : Error(error) {}
562 auto GetValue() const -> T const& {
return Value.GetValue(); }
568 operator TValueOrError<T, IErrorPtr>()
const
571 return MakeValue(Value.GetValue());
572 return MakeError(Error);
593#define ERROR_LOG(categoryName, verbosity, error) \
594 UE_LOG(categoryName, verbosity, TEXT("%s"), *((error) \
599#define ERROR_CLOG(condition, categoryName, verbosity, error) \
600 UE_CLOG(condition, categoryName, verbosity, TEXT("%s"), *((error) \
606#define ASSERT_RETURN(condition) \
607 if (UNLIKELY(!(condition))) \
608 return Mcro::Error::IError::Make(new Mcro::Error::FAssertion()) \
611 ->WithCodeContext(PREPROCESSOR_TO_TEXT(condition))
614#define UNAVAILABLE() \
615 return Mcro::Error::IError::Make(new Mcro::Error::FUnavailable()) \
624#define PROPAGATE_FAIL_TV(type, var, expression) \
625 type var = (expression); \
626 if (UNLIKELY(var.HasError())) return var.GetError() \
633#define PROPAGATE_FAIL_V(var, expression) PROPAGATE_FAIL_TV(auto, var, expression)
639#define PROPAGATE_FAIL(expression) PROPAGATE_FAIL_V(PREPROCESSOR_JOIN(tempResult, __LINE__), expression)
#define MCRO_DEBUG_BREAK()
FORCEINLINE int32 GetInnerErrorCount() const
virtual TSharedRef< SErrorDisplay > CreateErrorWidget()
SelfRef< Self > WithError(this Self &&self, const FString &name, const TSharedRef< Error > &input, bool condition=true)
SelfRef< Self > WithMessage(this Self &&self, const FString &input, bool condition=true)
SelfRef< Self > WithMessageFC(this Self &&self, bool condition, const TCHAR *input, FormatArgs &&... fmtArgs)
SelfRef< Self > WithCodeContext(this Self &&self, const FString &input, bool condition=true)
SelfRef< Self > WithErrors(this Self &&self, const TSharedRef< Errors > &... errors)
SelfRef< Self > WithAppendixF(this Self &&self, const FString &name, const TCHAR *text, FormatArgs &&... fmtArgs)
FStringView GetSeverityString() const
SelfRef< Self > WithDetails(this Self &&self, const FString &input, bool condition=true)
SelfRef< Self > Notify(this Self &&self, Observable::IState< IErrorPtr > &state)
SelfRef< Self > WithError(this Self &&self, const TSharedRef< Error > &input, bool condition=true)
std::string ToStringUtf8() const
virtual void SerializeYaml(YAML::Emitter &emitter, bool isRoot) const
SelfRef< Self > WithMessageF(this Self &&self, const TCHAR *input, FormatArgs &&... fmtArgs)
SelfRef< Self > WithSeverity(this Self &&self, EErrorSeverity input)
virtual void SerializeErrorPropagation(YAML::Emitter &emitter) const
FString GetErrorPropagationJoined() const
FORCEINLINE decltype(InnerErrors) ::TRangedForConstIterator end() const
void AddCppStackTrace(const FString &name, int32 numAdditionalStackFramesToIgnore, bool fastWalk)
FORCEINLINE FString const & GetCodeContext() const
FORCEINLINE decltype(InnerErrors) ::TRangedForConstIterator begin() const
SelfRef< Self > WithErrors(this Self &&self, bool condition, const TSharedRef< Errors > &... errors)
SelfRef< Self > AsFatal(this Self &&self)
FORCEINLINE FString const & GetMessage() const
TArray< std::source_location > ErrorPropagation
virtual void SerializeInnerErrors(YAML::Emitter &emitter) const
SelfRef< Self > AsRecoverable(this Self &&self)
SelfRef< Self > WithBlueprintStackTrace(this Self &&self, const FString &name={}, bool condition=true)
SelfRef< Self > WithAppendixFC(this Self &&self, bool condition, const FString &name, const TCHAR *text, FormatArgs &&... fmtArgs)
SelfRef< Self > WithDetailsF(this Self &&self, const TCHAR *input, FormatArgs &&... fmtArgs)
SelfRef< Self > BreakDebugger(this Self &&self)
FORCEINLINE FString const & GetDetails() const
FORCEINLINE decltype(InnerErrors) ::TRangedForIterator begin()
FORCEINLINE TMap< FString, IErrorRef > const & GetInnerErrors() const
FORCEINLINE decltype(InnerErrors) ::TRangedForIterator end()
SelfRef< Self > WithCppStackTrace(this Self &&self, const FString &name={}, bool condition=true, int32 numAdditionalStackFramesToIgnore=0, bool fastWalk=!UE_BUILD_DEBUG)
SelfRef< Self > WithAppendix(this Self &&self, const FString &name, const FString &text, bool condition=true)
SelfRef< Self > WithErrors(this Self &&self, const TArray< TTuple< FString, IErrorRef > > &input, bool condition=true)
static TSharedRef< T > Make(T *newError, Args &&... args)
virtual void AddError(const FString &name, const TSharedRef< IError > &error, const FString &typeOverride={})
TMap< FString, IErrorRef > InnerErrors
virtual void SerializeMembers(YAML::Emitter &emitter, bool isRoot) const
SelfRef< Self > WithDetailsFC(this Self &&self, bool condition, const TCHAR *input, FormatArgs &&... fmtArgs)
SelfRef< Self > WithLocation(this Self &&self, std::source_location location=std::source_location::current())
SelfRef< Self > AsCrashing(this Self &&self)
FORCEINLINE int32 GetSeverityInt() const
FORCEINLINE EErrorSeverity GetSeverity() const
void AddBlueprintStackTrace(const FString &name)
TArray< FString > GetErrorPropagation() const
virtual void NotifyState(Observable::IState< IErrorPtr > &state)
virtual void AddAppendix(const FString &name, const FString &text, const FString &type=TEXT("Appendix"))
TSharedRef< std::decay_t< Self > > SelfRef
FORCEINLINE FCanFail Success()
TSharedPtr< IError > IErrorPtr
TSharedRef< T, Mode > MakeShareableInit(T *newObject, Args &&... args)
MCRO_API FString DynamicPrintf(const TCHAR *fmt,...)
const FString TTypeString
TMaybe(TMaybe< From > const &other)
auto TryGetValue() const -> TOptional< T > const &
TMaybe(TSharedRef< ErrorType > const &error)
TMaybe(TMaybe< From > &&other)
auto GetError() const -> IErrorPtr
TMaybe(From const &value)
auto TryGetValue() -> TOptional< T > &
auto GetValue() const -> T const &