-
-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace git2::Exception with Result #1104
Comments
If I understand correctly, this is to replace |
Yes, correct |
Would something like this suffice? static Result<std::string> getAuthor() noexcept {
git2::Config config;
if (auto res = config.openDefault(); !res) {
logger::debug("Failed to open git config: {}", res.error().message());
return Err(to_anyhow(res.error().message()));
}
auto name = toml::try_find<std::string>(config, "user.name");
if (!name) {
logger::debug("Failed to get user.name: {}", name.error().message());
return Err(to_anyhow(name.error().message()));
}
auto email = toml::try_find<std::string>(config, "user.email");
if (!email) {
logger::debug("Failed to get user.email: {}", email.error().message());
return Err(to_anyhow(email.error().message()));
}
return Ok(*name + " <" + *email + ">");
}
|
Can’t we just return Result from git2 and propagate it via Try? |
How about this? My understanding is that static Result<std::string> getAuthor() noexcept {
git2::Config config;
Try(config.openDefault());
auto name = Try(toml::try_find<std::string>(config, "user.name"));
auto email = Try(toml::try_find<std::string>(config, "user.email"));
return Ok(name + " <" + email + ">");
}
|
getAuthor is not our interest in this issue. We’d like to modify git2 to use/return result, and all use of git2 will need to handle the returned result from git2 appropriately. In theory, we can make almost all functions in gut2 noexcept as a good side effect. |
No description provided.
The text was updated successfully, but these errors were encountered: