Skip to content

Commit

Permalink
Merge pull request #3223 from roggiezhang-nv/add_tenum_for_validation…
Browse files Browse the repository at this point in the history
…_error

Add `TfEnum` for validation error

(Internal change: 2337606)
  • Loading branch information
pixar-oss committed Aug 20, 2024
2 parents 8f53b21 + 102a3e2 commit 6480cb9
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions pxr/usd/usd/validationError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
// https://openusd.org/license.
//

#include "pxr/base/tf/enum.h"
#include "pxr/usd/usd/validationError.h"

PXR_NAMESPACE_OPEN_SCOPE

TF_REGISTRY_FUNCTION(TfEnum)
{
TF_ADD_ENUM_NAME(UsdValidationErrorType::None, "None");
TF_ADD_ENUM_NAME(UsdValidationErrorType::Error, "Error");
TF_ADD_ENUM_NAME(UsdValidationErrorType::Warn, "Warn");
TF_ADD_ENUM_NAME(UsdValidationErrorType::Info, "Info");
}

UsdValidationErrorSite::UsdValidationErrorSite(
const SdfLayerHandle &layer, const SdfPath &objectPath) :
_layer(layer), _objectPath(objectPath)
Expand Down Expand Up @@ -39,24 +48,8 @@ UsdValidationError::UsdValidationError(const UsdValidationErrorType &type,
std::string
UsdValidationError::GetErrorAsString() const
{
std::string errorTypeAsString;
switch(_errorType) {
case UsdValidationErrorType::None:
return _errorMsg;
break;
case UsdValidationErrorType::Error:
errorTypeAsString = "Error";
break;
case UsdValidationErrorType::Warn:
errorTypeAsString = "Warn";
break;
case UsdValidationErrorType::Info:
errorTypeAsString = "Info";
break;
}

const std::string separator = ": ";
return errorTypeAsString + separator + _errorMsg;
return _errorType == UsdValidationErrorType::None ? _errorMsg : TfStringPrintf(
"%s: %s", TfEnum::GetDisplayName(_errorType).c_str(), _errorMsg.c_str());
}

void
Expand Down

0 comments on commit 6480cb9

Please sign in to comment.