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

Side by Side Diff: sync/api/sync_error.cc

Issue 388003002: Sync: Display non-severe errors on about:sync in gray color rather than red. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 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 unified diff | Download patch
« sync/api/sync_error.h ('K') | « sync/api/sync_error.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/api/sync_error.h" 5 #include "sync/api/sync_error.h"
6 6
7 #include <ostream> 7 #include <ostream>
8 8
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "sync/internal_api/public/base/model_type.h" 11 #include "sync/internal_api/public/base/model_type.h"
12 12
13 namespace syncer { 13 namespace syncer {
14 14
15 SyncError::SyncError() { 15 SyncError::SyncError() {
16 Clear(); 16 Clear();
17 } 17 }
18 18
19 SyncError::SyncError(const tracked_objects::Location& location, 19 SyncError::SyncError(const tracked_objects::Location& location,
20 ErrorType error_type, 20 ErrorType error_type,
21 const std::string& custom_message, 21 const std::string& message,
22 ModelType model_type) { 22 ModelType model_type) {
23 std::string type_message; 23 CHECK(error_type != UNSET);
Nicolas Zea 2014/07/14 17:36:02 nit: prefer DCHECK vs CHECK, unless it's a securit
stanisc 2014/07/15 16:10:01 Done.
24 switch (error_type) { 24 Init(location, message, model_type, error_type);
25 case UNRECOVERABLE_ERROR:
26 type_message = "unrecoverable error was encountered: ";
27 break;
28 case DATATYPE_ERROR:
29 type_message = "datatype error was encountered: ";
30 break;
31 case PERSISTENCE_ERROR:
32 type_message = "persistence error was encountered: ";
33 break;
34 case CRYPTO_ERROR:
35 type_message = "cryptographer error was encountered: ";
36 break;
37 case UNREADY_ERROR:
38 type_message = "unready error was encountered: ";
39 break;
40 case UNSET:
41 NOTREACHED() << "Invalid error type";
42 return;
43 }
44 Init(location, type_message + custom_message, model_type, error_type);
45 PrintLogError(); 25 PrintLogError();
46 } 26 }
47 27
48 SyncError::SyncError(const SyncError& other) { 28 SyncError::SyncError(const SyncError& other) {
49 Copy(other); 29 Copy(other);
50 } 30 }
51 31
52 SyncError::~SyncError() { 32 SyncError::~SyncError() {
53 } 33 }
54 34
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ModelType SyncError::model_type() const { 93 ModelType SyncError::model_type() const {
114 CHECK(IsSet()); 94 CHECK(IsSet());
115 return model_type_; 95 return model_type_;
116 } 96 }
117 97
118 SyncError::ErrorType SyncError::error_type() const { 98 SyncError::ErrorType SyncError::error_type() const {
119 CHECK(IsSet()); 99 CHECK(IsSet());
120 return error_type_; 100 return error_type_;
121 } 101 }
122 102
103 logging::LogSeverity SyncError::severity() const {
Nicolas Zea 2014/07/14 17:36:02 nit: accessors should do nothing more than access
stanisc 2014/07/15 16:10:01 Done.
104 switch (error_type_) {
105 case UNREADY_ERROR:
106 case DATATYPE_POLICY_ERROR:
107 return logging::LOG_INFO;
108 default:
109 return logging::LOG_ERROR;
110 }
111 }
112
113 std::string SyncError::type_message_prefix() const {
114 std::string type_message;
115 switch (error_type_) {
116 case UNRECOVERABLE_ERROR:
117 type_message = "unrecoverable error was encountered: ";
118 break;
119 case DATATYPE_ERROR:
120 type_message = "datatype error was encountered: ";
121 break;
122 case PERSISTENCE_ERROR:
123 type_message = "persistence error was encountered: ";
124 break;
125 case CRYPTO_ERROR:
126 type_message = "cryptographer error was encountered: ";
127 break;
128 case UNREADY_ERROR:
129 type_message = "unready error was encountered: ";
130 break;
131 case DATATYPE_POLICY_ERROR:
132 type_message = "disabled due to configuration constraints: ";
133 break;
134 case UNSET:
135 NOTREACHED() << "Invalid error type";
136 break;
137 }
138 return type_message;
139 }
140
123 std::string SyncError::ToString() const { 141 std::string SyncError::ToString() const {
124 if (!IsSet()) { 142 if (!IsSet()) {
125 return std::string(); 143 return std::string();
126 } 144 }
127 return location_->ToString() + ", " + ModelTypeToString(model_type_) + 145 return location_->ToString() + ", " + ModelTypeToString(model_type_) +
128 " " + message_; 146 " " + type_message_prefix() + message_;
129 } 147 }
130 148
131 void SyncError::PrintLogError() const { 149 void SyncError::PrintLogError() const {
132 LAZY_STREAM(logging::LogMessage(location_->file_name(), 150 LAZY_STREAM(logging::LogMessage(location_->file_name(),
133 location_->line_number(), 151 location_->line_number(),
134 logging::LOG_ERROR).stream(), 152 severity()).stream(),
135 LOG_IS_ON(ERROR)) 153 severity() >= ::logging::GetMinLogLevel())
136 << ModelTypeToString(model_type_) << " " << message_; 154 << ModelTypeToString(model_type_) << " "
155 << type_message_prefix() << message_;
137 } 156 }
138 157
139 void PrintTo(const SyncError& sync_error, std::ostream* os) { 158 void PrintTo(const SyncError& sync_error, std::ostream* os) {
140 *os << sync_error.ToString(); 159 *os << sync_error.ToString();
141 } 160 }
142 161
143 } // namespace syncer 162 } // namespace syncer
OLDNEW
« sync/api/sync_error.h ('K') | « sync/api/sync_error.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698