Skip to content

Commit 8a30d77

Browse files
Add better logging for exceptions[OC-2817]
1 parent e294939 commit 8a30d77

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

core/src/registry.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
#include <algorithm>
44
#include <chrono>
5+
#include <iostream>
56
#include <iterator>
7+
#include <sstream>
68
#include <stdexcept>
79
#include <tuple>
810

@@ -108,8 +110,15 @@ Family<T>& Registry::Add(const std::string& name, const std::string& help,
108110
std::lock_guard<std::mutex> lock{mutex_};
109111

110112
if (NameExistsInOtherType<T>(name)) {
111-
throw std::invalid_argument(
112-
"Family name already exists with different type");
113+
std::stringstream ss;
114+
ss << "Family name already exists with different type (name:'" << name
115+
<< "',type:'" << typeid(T).name() << "');help:" << help << ";labels:";
116+
for (const auto& label : labels) {
117+
ss << label.first << "=" << label.second << ",";
118+
}
119+
ss << std::endl;
120+
std::cerr << ss.str();
121+
throw std::invalid_argument(ss.str());
113122
}
114123

115124
auto& families = GetFamilies<T>();
@@ -134,7 +143,15 @@ Family<T>& Registry::Add(const std::string& name, const std::string& help,
134143

135144
auto it = std::find_if(families.begin(), families.end(), same_name);
136145
if (it != families.end()) {
137-
throw std::invalid_argument("Family name already exists");
146+
std::stringstream ss;
147+
ss << "Family name already exists (name:'" << name
148+
<< "',type:'" << typeid(T).name() << "');help:" << help << ";labels:";
149+
for (const auto& label : labels) {
150+
ss << label.first << "=" << label.second << ",";
151+
}
152+
ss << std::endl;
153+
std::cerr << ss.str();
154+
throw std::invalid_argument(ss.str());
138155
}
139156

140157
auto family = detail::make_unique<Family<T>>(name, help, labels, ttl);

0 commit comments

Comments
 (0)