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
& message
,
22 ModelType model_type
) {
23 DCHECK(error_type
!= UNSET
);
24 Init(location
, message
, model_type
, error_type
);
28 SyncError::SyncError(const SyncError
& other
) {
32 SyncError::~SyncError() {
35 SyncError
& SyncError::operator=(const SyncError
& other
) {
43 void SyncError::Copy(const SyncError
& other
) {
45 Init(other
.location(),
54 void SyncError::Clear() {
56 message_
= std::string();
57 model_type_
= UNSPECIFIED
;
61 void SyncError::Reset(const tracked_objects::Location
& location
,
62 const std::string
& message
,
63 ModelType model_type
) {
64 Init(location
, message
, model_type
, DATATYPE_ERROR
);
68 void SyncError::Init(const tracked_objects::Location
& location
,
69 const std::string
& message
,
71 ErrorType error_type
) {
72 location_
.reset(new tracked_objects::Location(location
));
74 model_type_
= model_type
;
75 error_type_
= error_type
;
78 bool SyncError::IsSet() const {
79 return error_type_
!= UNSET
;
83 const tracked_objects::Location
& SyncError::location() const {
88 const std::string
& SyncError::message() const {
93 ModelType
SyncError::model_type() const {
98 SyncError::ErrorType
SyncError::error_type() const {
103 SyncError::Severity
SyncError::GetSeverity() const {
104 switch (error_type_
) {
106 case DATATYPE_POLICY_ERROR
:
107 return SYNC_ERROR_SEVERITY_INFO
;
109 return SYNC_ERROR_SEVERITY_ERROR
;
113 std::string
SyncError::GetMessagePrefix() const {
114 std::string type_message
;
115 switch (error_type_
) {
116 case UNRECOVERABLE_ERROR
:
117 type_message
= "unrecoverable error was encountered: ";
120 type_message
= "datatype error was encountered: ";
122 case PERSISTENCE_ERROR
:
123 type_message
= "persistence error was encountered: ";
126 type_message
= "cryptographer error was encountered: ";
129 type_message
= "unready error was encountered: ";
131 case DATATYPE_POLICY_ERROR
:
132 type_message
= "disabled due to configuration constraints: ";
135 NOTREACHED() << "Invalid error type";
141 std::string
SyncError::ToString() const {
143 return std::string();
145 return location_
->ToString() + ", " + ModelTypeToString(model_type_
) +
146 " " + GetMessagePrefix() + message_
;
149 void SyncError::PrintLogError() const {
150 logging::LogSeverity logSeverity
=
151 (GetSeverity() == SYNC_ERROR_SEVERITY_INFO
)
152 ? logging::LOG_VERBOSE
: logging::LOG_ERROR
;
154 LAZY_STREAM(logging::LogMessage(location_
->file_name(),
155 location_
->line_number(),
156 logSeverity
).stream(),
157 logSeverity
>= ::logging::GetMinLogLevel())
158 << ModelTypeToString(model_type_
) << " "
159 << GetMessagePrefix() << message_
;
162 void PrintTo(const SyncError
& sync_error
, std::ostream
* os
) {
163 *os
<< sync_error
.ToString();
166 } // namespace syncer