-
Notifications
You must be signed in to change notification settings - Fork 84
expected support error message #970
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,16 @@ class expected { | |
return val.value(); | ||
} | ||
|
||
const std::string& | ||
what() const { | ||
return msg; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel it would be better if the message is attached to a non success But now our Status is an enum class and cannot be extended. Would be a large change if we want to do that. See absl::Status for reference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In your proposed change to pass err_msg to the returned value of Search the code looks like this, which is pretty clumsy: expected<DataSetPtr> Search() const {
auto cfg = this->node->CreateConfig();
std::string err;
auto status = LoadConfig(cfg.get(), json, knowhere::SEARCH, "Search", &err);
if (err != Status::success) {
expected<DataSetPtr> ret(err);
ret << err;
return ret;
}
...
}
Status
LoadConfig(BaseConfig* cfg, const Json& json, knowhere::PARAM_TYPE param_type, const std::string& method, std::string* const err = nullptr) const {
Json json_(json);
auto res = Config::FormatAndCheck(*cfg, json_, err);
LOG_KNOWHERE_DEBUG_ << method << " config dump: " << json_.dump();
RETURN_IF_ERROR(res);
return Config::Load(*cfg, json_, param_type, err);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. change the return status, Leads to huge changes. |
||
|
||
void | ||
operator<<(const std::string& msg) { | ||
this->msg += msg; | ||
} | ||
|
||
expected<T>& | ||
operator=(const Status& err) { | ||
assert(err != Status::success); | ||
|
@@ -93,6 +103,7 @@ class expected { | |
private: | ||
std::optional<T> val = std::nullopt; | ||
std::optional<Status> err = std::nullopt; | ||
std::string msg; | ||
}; | ||
|
||
// Evaluates expr that returns a Status. Does nothing if the returned Status is | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider creating a temp string for both LOG_KNOWHERE_ERROR_ and assigning to err_msg? may be cleaner if we avoid repeating the formatting code twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good advice, but the code maybe looks weird.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO the below looks slightly better? Unless we have a good reason to have different messages for the logging/exception. Feel free to ignore this comment if you insist.