1 | // Copyright (c) 2011 The LevelDB 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. See the AUTHORS file for names of contributors. |
4 | // |
5 | // A Status encapsulates the result of an operation. It may indicate success, |
6 | // or it may indicate an error with an associated error message. |
7 | // |
8 | // Multiple threads can invoke const methods on a Status without |
9 | // external synchronization, but if any of the threads may call a |
10 | // non-const method, all threads accessing the same Status must use |
11 | // external synchronization. |
12 | |
13 | #include "arrow/status.h" |
14 | |
15 | #include <assert.h> |
16 | #include <sstream> |
17 | |
18 | namespace arrow { |
19 | |
20 | Status::Status(StatusCode code, const std::string& msg) { |
21 | assert(code != StatusCode::OK); |
22 | state_ = new State; |
23 | state_->code = code; |
24 | state_->msg = msg; |
25 | } |
26 | |
27 | void Status::CopyFrom(const Status& s) { |
28 | delete state_; |
29 | if (s.state_ == nullptr) { |
30 | state_ = nullptr; |
31 | } else { |
32 | state_ = new State(*s.state_); |
33 | } |
34 | } |
35 | |
36 | std::string Status::CodeAsString() const { |
37 | if (state_ == nullptr) { |
38 | return "OK"; |
39 | } |
40 | |
41 | const char* type; |
42 | switch (code()) { |
43 | case StatusCode::OK: |
44 | type = "OK"; |
45 | break; |
46 | case StatusCode::OutOfMemory: |
47 | type = "Out of memory"; |
48 | break; |
49 | case StatusCode::KeyError: |
50 | type = "Key error"; |
51 | break; |
52 | case StatusCode::TypeError: |
53 | type = "Type error"; |
54 | break; |
55 | case StatusCode::Invalid: |
56 | type = "Invalid"; |
57 | break; |
58 | case StatusCode::IOError: |
59 | type = "IOError"; |
60 | break; |
61 | case StatusCode::CapacityError: |
62 | type = "Capacity error"; |
63 | break; |
64 | case StatusCode::UnknownError: |
65 | type = "Unknown error"; |
66 | break; |
67 | case StatusCode::NotImplemented: |
68 | type = "NotImplemented"; |
69 | break; |
70 | case StatusCode::SerializationError: |
71 | type = "Serialization error"; |
72 | break; |
73 | case StatusCode::PythonError: |
74 | type = "Python error"; |
75 | break; |
76 | case StatusCode::PlasmaObjectExists: |
77 | type = "Plasma object exists"; |
78 | break; |
79 | case StatusCode::PlasmaObjectNonexistent: |
80 | type = "Plasma object is nonexistent"; |
81 | break; |
82 | case StatusCode::PlasmaStoreFull: |
83 | type = "Plasma store is full"; |
84 | break; |
85 | case StatusCode::PlasmaObjectAlreadySealed: |
86 | type = "Plasma object is already sealed"; |
87 | break; |
88 | case StatusCode::CodeGenError: |
89 | type = "CodeGenError in Gandiva"; |
90 | break; |
91 | case StatusCode::ExpressionValidationError: |
92 | type = "ExpressionValidationError"; |
93 | break; |
94 | case StatusCode::ExecutionError: |
95 | type = "ExecutionError in Gandiva"; |
96 | break; |
97 | default: |
98 | type = "Unknown"; |
99 | break; |
100 | } |
101 | return std::string(type); |
102 | } |
103 | |
104 | std::string Status::ToString() const { |
105 | std::string result(CodeAsString()); |
106 | if (state_ == NULL) { |
107 | return result; |
108 | } |
109 | result += ": "; |
110 | result += state_->msg; |
111 | return result; |
112 | } |
113 | |
114 | } // namespace arrow |
115 |