From 81d927bfc7e1e4c7b28aabdb0c64a12cec2833fe Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Fri, 27 Jul 2018 14:03:25 -0700 Subject: Adding NodeDef names to error messages for better debuggability. The format used is as follows: {{node }} PiperOrigin-RevId: 206370355 --- tensorflow/core/lib/core/errors.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tensorflow/core/lib') diff --git a/tensorflow/core/lib/core/errors.h b/tensorflow/core/lib/core/errors.h index 51c09032df..a631d9815a 100644 --- a/tensorflow/core/lib/core/errors.h +++ b/tensorflow/core/lib/core/errors.h @@ -19,6 +19,7 @@ limitations under the License. #include #include "tensorflow/core/lib/core/status.h" +#include "tensorflow/core/lib/strings/str_util.h" #include "tensorflow/core/lib/strings/strcat.h" #include "tensorflow/core/platform/logging.h" #include "tensorflow/core/platform/macros.h" @@ -118,6 +119,25 @@ DECLARE_ERROR(Unauthenticated, UNAUTHENTICATED) #undef DECLARE_ERROR +// Produces a formatted string pattern from the name which can uniquely identify +// this node upstream to produce an informative error message. The pattern +// followed is: {{node }} +// Note: The pattern below determines the regex _NODEDEF_NAME_RE in the file +// tensorflow/python/client/session.py +// LINT.IfChange +inline string FormatNodeNameForError(const string& name) { + return strings::StrCat("{{node ", name, "}}"); +} +// LINT.ThenChange(//tensorflow/python/client/session.py) +template +string FormatNodeNamesForError(const T& names) { + ::tensorflow::str_util::Formatter f( + [](string* output, const string& s) { + ::tensorflow::strings::StrAppend(output, FormatNodeNameForError(s)); + }); + return ::tensorflow::str_util::Join(names, ", ", f); +} + // The CanonicalCode() for non-errors. using ::tensorflow::error::OK; -- cgit v1.2.3