-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathstatus.cc
82 lines (69 loc) · 2.1 KB
/
status.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
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/test/chromedriver/status.h"
namespace {
// Returns the string equivalent of the given |ErrorCode|.
const char* DefaultMessageForStatusCode(StatusCode code) {
switch (code) {
case kOk:
return "ok";
case kNoSuchElement:
return "no such element";
case kUnknownCommand:
return "unknown command";
case kStaleElementReference:
return "stale element reference";
case kElementNotVisible:
return "element not visible";
case kInvalidElementState:
return "invalid element state";
case kUnknownError:
return "unknown error";
case kXPathLookupError:
return "xpath lookup error";
case kInvalidSelector:
return "invalid selector";
case kSessionNotCreatedException:
return "session not created exception";
case kNoSuchSession:
return "no such session";
case kChromeNotReachable:
return "chrome not reachable";
case kDisconnected:
return "disconnected";
default:
return "<unknown>";
}
}
} // namespace
Status::Status(StatusCode code)
: code_(code), msg_(DefaultMessageForStatusCode(code)) {}
Status::Status(StatusCode code, const std::string& details)
: code_(code),
msg_(DefaultMessageForStatusCode(code) + std::string(": ") + details) {
}
Status::Status(StatusCode code, const Status& cause)
: code_(code),
msg_(DefaultMessageForStatusCode(code) + std::string("\nfrom ") +
cause.message()) {}
Status::Status(StatusCode code,
const std::string& details,
const Status& cause)
: code_(code),
msg_(DefaultMessageForStatusCode(code) + std::string(": ") + details +
"\nfrom " + cause.message()) {
}
Status::~Status() {}
bool Status::IsOk() const {
return code_ == kOk;
}
bool Status::IsError() const {
return code_ != kOk;
}
StatusCode Status::code() const {
return code_;
}
const std::string& Status::message() const {
return msg_;
}