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
3 // found in the LICENSE file.
5 #include "sync/api/sync_error.h"
9 #include "base/location.h"
10 #include "base/logging.h"
11 #include "sync/internal_api/public/base/model_type.h"
15 SyncError::SyncError() {
19 SyncError::SyncError(const tracked_objects::Location& location,
21 const std::string& custom_message,
22 ModelType model_type) {
23 std::string type_message;
25 case UNRECOVERABLE_ERROR:
26 type_message = "unrecoverable error was encountered: ";
29 type_message = "datatype error was encountered: ";
31 case PERSISTENCE_ERROR:
32 type_message = "persistence error was encountered: ";
35 type_message = "cryptographer error was encountered: ";
39 type_message = "invalid error: ";
41 Init(location, type_message + custom_message, model_type, error_type);
45 SyncError::SyncError(const SyncError& other) {
49 SyncError::~SyncError() {
52 SyncError& SyncError::operator=(const SyncError& other) {
60 void SyncError::Copy(const SyncError& other) {
62 Init(other.location(),
71 void SyncError::Clear() {
73 message_ = std::string();
74 model_type_ = UNSPECIFIED;
78 void SyncError::Reset(const tracked_objects::Location& location,
79 const std::string& message,
80 ModelType model_type) {
81 Init(location, message, model_type, DATATYPE_ERROR);
85 void SyncError::Init(const tracked_objects::Location& location,
86 const std::string& message,
88 ErrorType error_type) {
89 location_.reset(new tracked_objects::Location(location));
91 model_type_ = model_type;
92 error_type_ = error_type;
95 bool SyncError::IsSet() const {
96 return error_type_ != UNSET;
100 const tracked_objects::Location& SyncError::location() const {
105 const std::string& SyncError::message() const {
110 ModelType SyncError::model_type() const {
115 SyncError::ErrorType SyncError::error_type() const {
120 std::string SyncError::ToString() const {
122 return std::string();
124 return location_->ToString() + ", " + ModelTypeToString(model_type_) +
128 void SyncError::PrintLogError() const {
129 LAZY_STREAM(logging::LogMessage(location_->file_name(),
130 location_->line_number(),
131 logging::LOG_ERROR).stream(),
133 << ModelTypeToString(model_type_) << " " << message_;
136 void PrintTo(const SyncError& sync_error, std::ostream* os) {
137 *os << sync_error.ToString();
140 } // namespace syncer