Index: sync/api/sync_error.cc |
diff --git a/sync/api/sync_error.cc b/sync/api/sync_error.cc |
index 12090404d1670f03670b89c9deca0b829c58c238..63090dd8b73073c53f87d161bc928a83b908656f 100644 |
--- a/sync/api/sync_error.cc |
+++ b/sync/api/sync_error.cc |
@@ -18,8 +18,33 @@ SyncError::SyncError() { |
SyncError::SyncError(const tracked_objects::Location& location, |
const std::string& message, |
- ModelType type) { |
- Init(location, message, type); |
+ ModelType model_type) { |
+ Init(location, message, model_type, DATATYPE_ERROR); |
+ PrintLogError(); |
+} |
+ |
+SyncError::SyncError(const tracked_objects::Location& location, |
+ ErrorType error_type, |
+ ModelType model_type) { |
+ std::string message; |
+ switch (error_type) { |
+ case UNRECOVERABLE_ERROR: |
+ message = "a unrecoverable error was encountered."; |
+ break; |
+ case DATATYPE_ERROR: |
+ message = "a datatype error was encountered."; |
+ break; |
+ case PERSISTENCE_ERROR: |
+ message = "a persistence error was encountered."; |
+ break; |
+ case CRYPTO_ERROR: |
+ message = "a cryptographer error was encountered."; |
+ break; |
+ default: |
+ NOTREACHED(); |
+ message = "invalid error."; |
+ } |
+ Init(location, message, model_type, error_type); |
PrintLogError(); |
} |
@@ -42,7 +67,8 @@ void SyncError::Copy(const SyncError& other) { |
if (other.IsSet()) { |
Init(other.location(), |
other.message(), |
- other.type()); |
+ other.model_type(), |
+ other.error_type()); |
} else { |
Clear(); |
} |
@@ -51,26 +77,29 @@ void SyncError::Copy(const SyncError& other) { |
void SyncError::Clear() { |
location_.reset(); |
message_ = std::string(); |
- type_ = UNSPECIFIED; |
+ model_type_ = UNSPECIFIED; |
+ error_type_ = UNSET; |
} |
void SyncError::Reset(const tracked_objects::Location& location, |
const std::string& message, |
- ModelType type) { |
- Init(location, message, type); |
+ ModelType model_type) { |
+ Init(location, message, model_type, DATATYPE_ERROR); |
PrintLogError(); |
} |
void SyncError::Init(const tracked_objects::Location& location, |
const std::string& message, |
- ModelType type) { |
+ ModelType model_type, |
+ ErrorType error_type) { |
location_.reset(new tracked_objects::Location(location)); |
message_ = message; |
- type_ = type; |
+ model_type_ = model_type; |
+ error_type_ = error_type; |
} |
bool SyncError::IsSet() const { |
- return location_.get() != NULL; |
+ return error_type_ != UNSET; |
} |
@@ -84,16 +113,21 @@ const std::string& SyncError::message() const { |
return message_; |
} |
-ModelType SyncError::type() const { |
+ModelType SyncError::model_type() const { |
+ CHECK(IsSet()); |
+ return model_type_; |
+} |
+ |
+SyncError::ErrorType SyncError::error_type() const { |
CHECK(IsSet()); |
- return type_; |
+ return error_type_; |
} |
std::string SyncError::ToString() const { |
if (!IsSet()) { |
return std::string(); |
} |
- return location_->ToString() + ", " + ModelTypeToString(type_) + |
+ return location_->ToString() + ", " + ModelTypeToString(model_type_) + |
", Sync Error: " + message_; |
} |
@@ -102,7 +136,7 @@ void SyncError::PrintLogError() const { |
location_->line_number(), |
logging::LOG_ERROR).stream(), |
LOG_IS_ON(ERROR)) |
- << ModelTypeToString(type_) << ", Sync Error: " << message_; |
+ << ModelTypeToString(model_type_) << ", Sync Error: " << message_; |
} |
void PrintTo(const SyncError& sync_error, std::ostream* os) { |