-
Notifications
You must be signed in to change notification settings - Fork 1
/
error.cc
111 lines (80 loc) · 2.92 KB
/
error.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Copyright 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifdef NATIVE_BUILD
#include <ostream>
#include "error.h"
#else // NATIVE_BUILD
#include <Error.h>
#endif // NATIVE_BUILD
namespace error {
Error::Error(Code canonical_code, int library_number, int error_number,
int subcode)
: canonical_code_(canonical_code), library_number_(library_number),
error_number_(error_number), subcode_(subcode) {}
Error::Error(Code canonical_code, int library_number, int error_number)
: Error(canonical_code, library_number, error_number, kUnspecified) {}
Error::Error(Code canonical_code, int library_number)
: Error(canonical_code, library_number, kUnspecified, kUnspecified) {}
Error::Error(Code canonical_code)
: Error(canonical_code, kUnspecified, kUnspecified, kUnspecified) {}
Error::Error() : Error(Error::OK, kUnspecified, kUnspecified, kUnspecified) {}
Error::~Error() {}
bool Error::Ok() const { return canonical_code_ == Error::OK; }
Error::Code Error::CanonicalCode() const { return canonical_code_; }
const Error &Error::GetError() const { return *this; }
int Error::LibraryNumber() const { return library_number_; }
int Error::ErrorNumber() const { return error_number_; }
int Error::Subcode() const { return subcode_; }
bool Error::operator==(const Error &other) const {
return (CanonicalCode() == other.CanonicalCode() &&
LibraryNumber() == other.LibraryNumber() &&
ErrorNumber() == other.ErrorNumber() && Subcode() == other.Subcode());
}
bool Error::operator!=(const Error &other) const { return !(*this == other); }
#ifdef NATIVE_BUILD
void PrintTo(const Error &error, ::std::ostream *os) {
*os << "Error(Code:";
switch (error.CanonicalCode()) {
case Error::OK:
*os << "OK";
break;
case Error::INVALID_ARGUMENT:
*os << "INVALID_ARGUMENT";
break;
case Error::INTERNAL_ERROR:
*os << "INTERNAL_ERROR";
break;
case Error::UNIMPLEMENTED:
*os << "UNIMPLEMENTED";
break;
case Error::UNKNOWN:
*os << "UNKNOWN";
break;
default:
*os << error.CanonicalCode();
break;
}
if (error.LibraryNumber() != kUnspecified) {
*os << " LibraryNumber:" << error.LibraryNumber();
}
if (error.ErrorNumber() != kUnspecified) {
*os << " ErrorNumber:" << error.ErrorNumber();
}
if (error.Subcode() != kUnspecified) {
*os << " Subcode:" << error.Subcode();
}
*os << ")";
}
#endif
} // namespace error