From a1e73879199eea7c271ebfff411f51323a7f5207 Mon Sep 17 00:00:00 2001 From: yiicy Date: Tue, 14 Apr 2020 18:57:20 +0800 Subject: [PATCH] Variable error message enhancement, test=develop (#23548) --- paddle/fluid/framework/variable.h | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/paddle/fluid/framework/variable.h b/paddle/fluid/framework/variable.h index 75d2f32d73..cf788ab013 100644 --- a/paddle/fluid/framework/variable.h +++ b/paddle/fluid/framework/variable.h @@ -30,11 +30,13 @@ class Variable { static_assert( IsRegisteredVarType(), "Not registered type. Please register T inside var_type_traits.h"); - PADDLE_ENFORCE(holder_ != nullptr, "Variable is not initialized."); - PADDLE_ENFORCE(holder_->Type() == VarTypeTrait::kId, - "The Variable type must be %s, but the type it holds is %s.", - ToTypeName(VarTypeTrait::kId), - ToTypeName(holder_->Type())); + PADDLE_ENFORCE_NOT_NULL( + holder_, platform::errors::NotFound("Variable is not initialized.")); + PADDLE_ENFORCE_EQ( + holder_->Type(), VarTypeTrait::kId, + platform::errors::InvalidArgument( + "The Variable type must be %s, but the type it holds is %s.", + ToTypeName(VarTypeTrait::kId), ToTypeName(holder_->Type()))); return *static_cast(holder_->Ptr()); } @@ -45,10 +47,11 @@ class Variable { if (!holder_) { holder_.reset(new PlaceholderImpl()); } else { - PADDLE_ENFORCE( - holder_->Type() == VarTypeTrait::kId, - "The Variable type must be %s, but the type it holds is %s.", - ToTypeName(VarTypeTrait::kId), ToTypeName(holder_->Type())); + PADDLE_ENFORCE_EQ( + holder_->Type(), VarTypeTrait::kId, + platform::errors::InvalidArgument( + "The Variable type must be %s, but the type it holds is %s.", + ToTypeName(VarTypeTrait::kId), ToTypeName(holder_->Type()))); } return static_cast(holder_->Ptr()); } @@ -61,7 +64,8 @@ class Variable { void Clear() { holder_.reset(); } int Type() const { - PADDLE_ENFORCE(holder_ != nullptr, "Variable is not initialized."); + PADDLE_ENFORCE_NOT_NULL( + holder_, platform::errors::NotFound("Variable is not initialized.")); return holder_->Type(); } -- GitLab