Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(753)

Unified Diff: headless/public/util/error_reporter.cc

Issue 1867753005: headless: Add error reporter utility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK that path has no more components Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « headless/public/util/error_reporter.h ('k') | headless/public/util/error_reporter_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: headless/public/util/error_reporter.cc
diff --git a/headless/public/util/error_reporter.cc b/headless/public/util/error_reporter.cc
new file mode 100644
index 0000000000000000000000000000000000000000..54c0758b71ddd940e3ff76aee3cdc62cefea3203
--- /dev/null
+++ b/headless/public/util/error_reporter.cc
@@ -0,0 +1,51 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "headless/public/util/error_reporter.h"
+
+#include <sstream>
+
+#include "base/logging.h"
+
+namespace headless {
+
+ErrorReporter::ErrorReporter() {}
+
+ErrorReporter::~ErrorReporter() {}
+
+void ErrorReporter::Push() {
+ path_.push_back(nullptr);
+}
+
+void ErrorReporter::Pop() {
+ path_.pop_back();
+}
+
+void ErrorReporter::SetName(const char* name) {
+ DCHECK(!path_.empty());
+ path_[path_.size() - 1] = name;
+}
+
+void ErrorReporter::AddError(base::StringPiece description) {
+ std::stringstream error;
+ for (size_t i = 0; i < path_.size(); i++) {
+ if (!path_[i]) {
+ DCHECK_EQ(i + 1, path_.size());
+ break;
+ }
+ if (i)
+ error << '.';
+ error << path_[i];
+ }
+ if (error.tellp())
+ error << ": ";
+ error << description;
+ errors_.push_back(error.str());
+}
+
+bool ErrorReporter::HasErrors() const {
+ return !errors_.empty();
+}
+
+} // namespace headless
« no previous file with comments | « headless/public/util/error_reporter.h ('k') | headless/public/util/error_reporter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698