forked from aristanetworks/EosSdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception.cpp
59 lines (48 loc) · 2.06 KB
/
exception.cpp
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
// Copyright (c) 2014 Arista Networks, Inc. All rights reserved.
// Arista Networks, Inc. Confidential and Proprietary.
#include <string>
#include <sstream>
#include "eos/exception.h"
namespace eos {
// This file contains non-inlined constructors because the constructors
// contain literal strings. Should they be inlined, there would be one
// copy of each string used in each translation unit, which contributes
// to increased binary size.
invalid_argument_error::invalid_argument_error(
std::string const & argument_name) noexcept
: error(std::string("Invalid argument '" + argument_name + "'")),
argument_name_(argument_name) {
}
invalid_argument_error::invalid_argument_error(
std::string const & argument_name,
std::string const & error_details) noexcept
: error(std::string("Invalid argument '" + argument_name +
"': " + error_details)),
argument_name_(argument_name) {
}
static inline std::string
invalid_range_error_msg(uint32_t min_valid, uint32_t max_valid) {
std::stringstream str;
str << "value is outside its valid range. min_valid = "
<< min_valid << ", max_valid = " << max_valid;
return str.str();
}
invalid_range_error::invalid_range_error(std::string const & argument_name,
uint32_t min_valid, uint32_t max_valid)
noexcept
: invalid_argument_error(argument_name,
invalid_range_error_msg(min_valid, max_valid)),
min_valid_(min_valid), max_valid_(max_valid) {
}
static
inline std::string unconfigured_agent_error_msg(std::string const & agent_name) {
std::stringstream str;
str << "The agent " << agent_name.c_str() << " has not been configured. "
"Ensure that the agent has been configured to run from the CLI and "
"that the executable uses the same agent name.";
return str.str();
}
unconfigured_agent_error::unconfigured_agent_error(std::string const & name) noexcept
: configuration_error(unconfigured_agent_error_msg(name)), agent_name_(name) {
}
}