Skip to content

Commit

Permalink
Fixed issues 1
Browse files Browse the repository at this point in the history
  • Loading branch information
GrigoriyPA committed Dec 10, 2024
1 parent 8d645d1 commit e7c31b6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 38 deletions.
20 changes: 6 additions & 14 deletions ydb/library/conclusion/generic/result.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ class TConclusionImpl {

const TResult& GetResult() const {
auto result = std::get_if<TResult>(&Result);
Y_ABORT_UNLESS(result, "incorrect object for result request: %s", GetErrorString().data());
Y_ABORT_UNLESS(result, "incorrect object for result request: %s", GetErrorMessage().data());
return *result;
}

TResult& MutableResult() {
auto result = std::get_if<TResult>(&Result);
Y_ABORT_UNLESS(result, "incorrect object for result request: %s", GetErrorString().data());
Y_ABORT_UNLESS(result, "incorrect object for result request: %s", GetErrorMessage().data());
return *result;
}

TResult&& DetachResult() {
auto result = std::get_if<TResult>(&Result);
Y_ABORT_UNLESS(result, "incorrect object for result request: %s", GetErrorString().data());
Y_ABORT_UNLESS(result, "incorrect object for result request: %s", GetErrorMessage().data());
return std::move(*result);
}

Expand All @@ -92,18 +92,10 @@ class TConclusionImpl {
return GetError();
}

TString GetErrorString() const {
TString GetErrorMessage() const {
auto* status = std::get_if<TStatus>(&Result);
return status ? status->GetErrorString() : Default<TString>();
}

const auto& GetErrorMessage() const {
auto* status = std::get_if<TStatus>(&Result);
if (!status) {
return TStatus::Success().GetErrorMessage();
} else {
return status->GetErrorMessage();
}
Y_ABORT_UNLESS(status, "incorrect object for extracting error message");
return status->GetErrorMessage();
}

auto GetStatus() const {
Expand Down
48 changes: 24 additions & 24 deletions ydb/library/conclusion/generic/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,32 @@

namespace NKikimr {

template <class TStatus, TStatus StatusOk, TStatus DefaultError, class TError, class TDerived>
template <class TDerived, class TError, class TStatus, TStatus StatusOk, TStatus DefaultError>
class TConclusionStatusGenericImpl {
protected:
std::optional<TError> ErrorMessage;
std::optional<TError> ErrorDescription;
TStatus Status = StatusOk;

TConclusionStatusGenericImpl() = default;

TConclusionStatusGenericImpl(const TError& error, TStatus status = DefaultError)
: ErrorMessage(error)
: ErrorDescription(error)
, Status(status) {
Y_ABORT_UNLESS(!!ErrorMessage);
Y_ABORT_UNLESS(!!ErrorDescription);
}

TConclusionStatusGenericImpl(TError&& error, TStatus status = DefaultError)
: ErrorMessage(std::move(error))
: ErrorDescription(std::move(error))
, Status(status) {
Y_ABORT_UNLESS(!!ErrorMessage);
Y_ABORT_UNLESS(!!ErrorDescription);
}

public:
virtual ~TConclusionStatusGenericImpl() = default;

public:
[[nodiscard]] const TError& GetErrorMessage() const {
return ErrorMessage ? *ErrorMessage : Default<TError>();
}

[[nodiscard]] virtual TString GetErrorString() const {
return ErrorMessage ? ToString(*ErrorMessage) : Default<TString>();
[[nodiscard]] const TError& GetErrorDescription() const {
return ErrorDescription ? *ErrorDescription : Default<TError>();
}

[[nodiscard]] TStatus GetStatus() const {
Expand All @@ -66,11 +62,11 @@ class TConclusionStatusGenericImpl {
}

[[nodiscard]] bool Ok() const {
return !ErrorMessage;
return !ErrorDescription;
}

[[nodiscard]] bool operator!() const {
return !!ErrorMessage;
return !!ErrorDescription;
}

[[nodiscard]] static TDerived Success() {
Expand All @@ -79,13 +75,13 @@ class TConclusionStatusGenericImpl {
};

template <class TStatus, TStatus StatusOk, TStatus DefaultError>
class TConclusionStatusImpl : public TConclusionStatusGenericImpl<TStatus, StatusOk, DefaultError, TString, TConclusionStatusImpl<TStatus, StatusOk, DefaultError>> {
class TConclusionStatusImpl : public TConclusionStatusGenericImpl<TConclusionStatusImpl<TStatus, StatusOk, DefaultError>, TString, TStatus, StatusOk, DefaultError> {
protected:
using TSelf = TConclusionStatusImpl<TStatus, StatusOk, DefaultError>;
using TBase = TConclusionStatusGenericImpl<TStatus, StatusOk, DefaultError, TString, TSelf>;
using TBase = TConclusionStatusGenericImpl<TSelf, TString, TStatus, StatusOk, DefaultError>;
using TBase::TBase;

friend class TConclusionStatusGenericImpl<TStatus, StatusOk, DefaultError, TString, TSelf>;
friend class TConclusionStatusGenericImpl<TSelf, TString, TStatus, StatusOk, DefaultError>;

TConclusionStatusImpl() = default;

Expand All @@ -100,21 +96,25 @@ class TConclusionStatusImpl : public TConclusionStatusGenericImpl<TStatus, Statu
public:
void Validate(const TString& processInfo = Default<TString>()) const {
if (processInfo) {
Y_ABORT_UNLESS(TBase::Ok(), "error=%s, processInfo=%s", TBase::GetErrorMessage().c_str(), processInfo.c_str());
Y_ABORT_UNLESS(TBase::Ok(), "error=%s, processInfo=%s", GetErrorMessage().c_str(), processInfo.c_str());
} else {
Y_ABORT_UNLESS(TBase::Ok(), "error=%s", TBase::GetErrorMessage().c_str());
Y_ABORT_UNLESS(TBase::Ok(), "error=%s", GetErrorMessage().c_str());
}
}

[[nodiscard]] TString GetErrorMessage() const {
return TBase::GetErrorDescription();
}
};

template <class TStatus, TStatus StatusOk, TStatus DefaultError>
class TYQLConclusionStatusImpl : public TConclusionStatusGenericImpl<TStatus, StatusOk, DefaultError, NYql::TIssues, TYQLConclusionStatusImpl<TStatus, StatusOk, DefaultError>> {
class TYQLConclusionStatusImpl : public TConclusionStatusGenericImpl<TYQLConclusionStatusImpl<TStatus, StatusOk, DefaultError>, NYql::TIssues, TStatus, StatusOk, DefaultError> {
protected:
using TSelf = TYQLConclusionStatusImpl<TStatus, StatusOk, DefaultError>;
using TBase = TConclusionStatusGenericImpl<TStatus, StatusOk, DefaultError, NYql::TIssues, TSelf>;
using TBase = TConclusionStatusGenericImpl<TSelf, NYql::TIssues, TStatus, StatusOk, DefaultError>;
using TBase::TBase;

friend class TConclusionStatusGenericImpl<TStatus, StatusOk, DefaultError, NYql::TIssues, TSelf>;
friend class TConclusionStatusGenericImpl<TSelf, NYql::TIssues, TStatus, StatusOk, DefaultError>;

TYQLConclusionStatusImpl() = default;

Expand Down Expand Up @@ -148,8 +148,8 @@ class TYQLConclusionStatusImpl : public TConclusionStatusGenericImpl<TStatus, St
return *this;
}

[[nodiscard]] virtual TString GetErrorString() const override {
return TBase::GetErrorMessage().ToOneLineString();
[[nodiscard]] TString GetErrorMessage() const {
return TBase::GetErrorDescription().ToOneLineString();
}
};

Expand Down

0 comments on commit e7c31b6

Please sign in to comment.