Use TRY_RESULT_ASSIGN.
GitOrigin-RevId: 99b60b9044fab9357a3440aed7da55f146677e6b
This commit is contained in:
parent
a0d761f27e
commit
8c495d99e6
@ -847,16 +847,14 @@ class MessagesDbImpl : public MessagesDbSyncInterface {
|
||||
left_cnt++;
|
||||
}
|
||||
|
||||
TRY_RESULT(left_tmp, get_messages_inner(stmt.desc_stmt_, dialog_id, left_message_id, left_cnt));
|
||||
left = std::move(left_tmp);
|
||||
TRY_RESULT_ASSIGN(left, get_messages_inner(stmt.desc_stmt_, dialog_id, left_message_id, left_cnt));
|
||||
|
||||
if (right_cnt == 1 && !left.empty() && false /*get_message_id(left[0].as_slice()) == message_id*/) {
|
||||
right_cnt = 0;
|
||||
}
|
||||
}
|
||||
if (right_cnt != 0) {
|
||||
TRY_RESULT(right_tmp, get_messages_inner(stmt.asc_stmt_, dialog_id, right_message_id, right_cnt));
|
||||
right = std::move(right_tmp);
|
||||
TRY_RESULT_ASSIGN(right, get_messages_inner(stmt.asc_stmt_, dialog_id, right_message_id, right_cnt));
|
||||
std::reverse(right.begin(), right.end());
|
||||
}
|
||||
if (left.empty()) {
|
||||
|
@ -3210,8 +3210,7 @@ Status NotificationManager::process_push_notification_payload(string payload, bo
|
||||
if (mtpeer.type() != JsonValue::Type::Null) {
|
||||
TRY_RESULT(ah, get_json_object_string_field(mtpeer.get_object(), "ah"));
|
||||
if (!ah.empty()) {
|
||||
TRY_RESULT(sender_access_hash_safe, to_integer_safe<int64>(ah));
|
||||
sender_access_hash = sender_access_hash_safe;
|
||||
TRY_RESULT_ASSIGN(sender_access_hash, to_integer_safe<int64>(ah));
|
||||
}
|
||||
TRY_RESULT(ph, get_json_object_field(mtpeer.get_object(), "ph", JsonValue::Type::Object));
|
||||
if (ph.type() != JsonValue::Type::Null) {
|
||||
|
@ -380,8 +380,8 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
|
||||
switch (button_type_id) {
|
||||
case td_api::inlineKeyboardButtonTypeUrl::ID: {
|
||||
current_button.type = InlineKeyboardButton::Type::Url;
|
||||
TRY_RESULT(url, check_url(static_cast<const td_api::inlineKeyboardButtonTypeUrl *>(button->type_.get())->url_));
|
||||
current_button.data = std::move(url);
|
||||
TRY_RESULT_ASSIGN(current_button.data,
|
||||
check_url(static_cast<const td_api::inlineKeyboardButtonTypeUrl *>(button->type_.get())->url_));
|
||||
if (!clean_input_string(current_button.data)) {
|
||||
return Status::Error(400, "Inline keyboard button url must be encoded in UTF-8");
|
||||
}
|
||||
@ -420,8 +420,7 @@ static Result<InlineKeyboardButton> get_inline_keyboard_button(tl_object_ptr<td_
|
||||
case td_api::inlineKeyboardButtonTypeLoginUrl::ID: {
|
||||
current_button.type = InlineKeyboardButton::Type::UrlAuth;
|
||||
auto login_url = td_api::move_object_as<td_api::inlineKeyboardButtonTypeLoginUrl>(button->type_);
|
||||
TRY_RESULT(url, check_url(login_url->url_));
|
||||
current_button.data = std::move(url);
|
||||
TRY_RESULT_ASSIGN(current_button.data, check_url(login_url->url_));
|
||||
current_button.forward_text = std::move(login_url->forward_text_);
|
||||
if (!clean_input_string(current_button.data)) {
|
||||
return Status::Error(400, "Inline keyboard button login url must be encoded in UTF-8");
|
||||
|
@ -892,19 +892,15 @@ static Result<SecureValue> get_identity_document(SecureValueType type, FileManag
|
||||
}
|
||||
}
|
||||
|
||||
TRY_RESULT(front_side, get_secure_file(file_manager, std::move(identity_document->front_side_)));
|
||||
res.front_side = std::move(front_side);
|
||||
TRY_RESULT_ASSIGN(res.front_side, get_secure_file(file_manager, std::move(identity_document->front_side_)));
|
||||
if (identity_document->reverse_side_ != nullptr) {
|
||||
TRY_RESULT(reverse_side, get_secure_file(file_manager, std::move(identity_document->reverse_side_)));
|
||||
res.reverse_side = std::move(reverse_side);
|
||||
TRY_RESULT_ASSIGN(res.reverse_side, get_secure_file(file_manager, std::move(identity_document->reverse_side_)));
|
||||
}
|
||||
if (identity_document->selfie_ != nullptr) {
|
||||
TRY_RESULT(selfie, get_secure_file(file_manager, std::move(identity_document->selfie_)));
|
||||
res.selfie = std::move(selfie);
|
||||
TRY_RESULT_ASSIGN(res.selfie, get_secure_file(file_manager, std::move(identity_document->selfie_)));
|
||||
}
|
||||
if (!identity_document->translation_.empty()) {
|
||||
TRY_RESULT(translations, get_secure_files(file_manager, std::move(identity_document->translation_)));
|
||||
res.translations = std::move(translations);
|
||||
TRY_RESULT_ASSIGN(res.translations, get_secure_files(file_manager, std::move(identity_document->translation_)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -962,11 +958,9 @@ static Result<SecureValue> get_personal_document(
|
||||
if (personal_document->files_.empty()) {
|
||||
return Status::Error(400, "Document's files are required");
|
||||
}
|
||||
TRY_RESULT(files, get_secure_files(file_manager, std::move(personal_document->files_)));
|
||||
res.files = std::move(files);
|
||||
TRY_RESULT_ASSIGN(res.files, get_secure_files(file_manager, std::move(personal_document->files_)));
|
||||
if (!personal_document->translation_.empty()) {
|
||||
TRY_RESULT(translations, get_secure_files(file_manager, std::move(personal_document->translation_)));
|
||||
res.translations = std::move(translations);
|
||||
TRY_RESULT_ASSIGN(res.translations, get_secure_files(file_manager, std::move(personal_document->translation_)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@ -1002,8 +996,7 @@ Result<SecureValue> get_secure_value(FileManager *file_manager,
|
||||
case td_api::inputPassportElementPersonalDetails::ID: {
|
||||
auto input = td_api::move_object_as<td_api::inputPassportElementPersonalDetails>(input_passport_element);
|
||||
res.type = SecureValueType::PersonalDetails;
|
||||
TRY_RESULT(personal_details, get_personal_details(std::move(input->personal_details_)));
|
||||
res.data = std::move(personal_details);
|
||||
TRY_RESULT_ASSIGN(res.data, get_personal_details(std::move(input->personal_details_)));
|
||||
break;
|
||||
}
|
||||
case td_api::inputPassportElementPassport::ID: {
|
||||
@ -1455,7 +1448,7 @@ static auto credentials_as_jsonable(const std::vector<SecureValueCredentials> &c
|
||||
}));
|
||||
}
|
||||
}));
|
||||
o(rename_payload_to_nonce ? "nonce" : "payload", nonce);
|
||||
o(rename_payload_to_nonce ? Slice("nonce") : Slice("payload"), nonce);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -135,8 +135,7 @@ Status FileDownloader::on_ok(int64 size) {
|
||||
if (only_check_) {
|
||||
path = path_;
|
||||
} else {
|
||||
TRY_RESULT(perm_path, create_from_temp(path_, dir, name_));
|
||||
path = std::move(perm_path);
|
||||
TRY_RESULT_ASSIGN(path, create_from_temp(path_, dir, name_));
|
||||
}
|
||||
callback_->on_ok(FullLocalFileLocation(remote_.file_type_, std::move(path), 0), size, !only_check_);
|
||||
return Status::OK();
|
||||
@ -492,11 +491,9 @@ void FileDownloader::try_release_fd() {
|
||||
Status FileDownloader::acquire_fd() {
|
||||
if (fd_.empty()) {
|
||||
if (path_.empty()) {
|
||||
TRY_RESULT(file_path, open_temp_file(remote_.file_type_));
|
||||
std::tie(fd_, path_) = std::move(file_path);
|
||||
TRY_RESULT_ASSIGN(std::tie(fd_, path_), open_temp_file(remote_.file_type_));
|
||||
} else {
|
||||
TRY_RESULT(fd, FileFd::open(path_, (only_check_ ? 0 : FileFd::Write) | FileFd::Read));
|
||||
fd_ = std::move(fd);
|
||||
TRY_RESULT_ASSIGN(fd_, FileFd::open(path_, (only_check_ ? 0 : FileFd::Write) | FileFd::Read));
|
||||
}
|
||||
}
|
||||
return Status::OK();
|
||||
|
@ -167,8 +167,7 @@ Result<FileLoader::PrefixInfo> FileUploader::on_update_local_location(const Loca
|
||||
}
|
||||
if (local_is_ready) {
|
||||
CHECK(!fd_.empty());
|
||||
TRY_RESULT(local_file_size, fd_.get_size());
|
||||
local_size = local_file_size;
|
||||
TRY_RESULT_ASSIGN(local_size, fd_.get_size());
|
||||
LOG(INFO) << "Set file local_size to " << local_size;
|
||||
if (local_size == 0) {
|
||||
return Status::Error("Can't upload empty file");
|
||||
@ -338,8 +337,7 @@ void FileUploader::try_release_fd() {
|
||||
|
||||
Status FileUploader::acquire_fd() {
|
||||
if (fd_.empty()) {
|
||||
TRY_RESULT(fd, FileFd::open(fd_path_, FileFd::Read));
|
||||
fd_ = std::move(fd);
|
||||
TRY_RESULT_ASSIGN(fd_, FileFd::open(fd_path_, FileFd::Read));
|
||||
}
|
||||
return Status::OK();
|
||||
}
|
||||
|
@ -685,8 +685,7 @@ Result<SocketFd> ConnectionCreator::find_connection(const Proxy &proxy, const IP
|
||||
TRY_RESULT(info, dc_options_set_.find_connection(
|
||||
dc_id, allow_media_only, proxy.use_proxy() && proxy.use_socks5_proxy(), prefer_ipv6, only_http));
|
||||
extra.stat = info.stat;
|
||||
TRY_RESULT(transport_type, get_transport_type(proxy, info));
|
||||
extra.transport_type = std::move(transport_type);
|
||||
TRY_RESULT_ASSIGN(extra.transport_type, get_transport_type(proxy, info));
|
||||
|
||||
extra.debug_str = PSTRING() << " to " << (info.option->is_media_only() ? "MEDIA " : "") << dc_id
|
||||
<< (info.use_http ? " over HTTP" : "");
|
||||
|
@ -81,8 +81,7 @@ inline Status from_json(int32 &to, JsonValue &from) {
|
||||
return Status::Error(PSLICE() << "Expected Number, got " << from.type());
|
||||
}
|
||||
Slice number = from.type() == JsonValue::Type::String ? from.get_string() : from.get_number();
|
||||
TRY_RESULT(res, to_integer_safe<int32>(number));
|
||||
to = res;
|
||||
TRY_RESULT_ASSIGN(to, to_integer_safe<int32>(number));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -105,8 +104,7 @@ inline Status from_json(int64 &to, JsonValue &from) {
|
||||
return Status::Error(PSLICE() << "Expected String or Number, got " << from.type());
|
||||
}
|
||||
Slice number = from.type() == JsonValue::Type::String ? from.get_string() : from.get_number();
|
||||
TRY_RESULT(res, to_integer_safe<int64>(number));
|
||||
to = res;
|
||||
TRY_RESULT_ASSIGN(to, to_integer_safe<int64>(number));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -130,8 +128,7 @@ inline Status from_json_bytes(string &to, JsonValue &from) {
|
||||
if (from.type() != JsonValue::Type::String) {
|
||||
return Status::Error(PSLICE() << "Expected String, got " << from.type());
|
||||
}
|
||||
TRY_RESULT(decoded, base64_decode(from.get_string()));
|
||||
to = std::move(decoded);
|
||||
TRY_RESULT_ASSIGN(to, base64_decode(from.get_string()));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -180,8 +177,7 @@ std::enable_if_t<!std::is_constructible<T>::value, Status> from_json(tl_object_p
|
||||
if (constructor_value.type() == JsonValue::Type::Number) {
|
||||
constructor = to_integer<int32>(constructor_value.get_number());
|
||||
} else if (constructor_value.type() == JsonValue::Type::String) {
|
||||
TRY_RESULT(t_constructor, tl_constructor_from_string(to.get(), constructor_value.get_string().str()));
|
||||
constructor = t_constructor;
|
||||
TRY_RESULT_ASSIGN(constructor, tl_constructor_from_string(to.get(), constructor_value.get_string().str()));
|
||||
} else {
|
||||
return Status::Error(PSLICE() << "Expected String or Integer, got " << constructor_value.type());
|
||||
}
|
||||
|
@ -38,8 +38,7 @@ Wget::Wget(Promise<unique_ptr<HttpQuery>> promise, string url, std::vector<std::
|
||||
|
||||
Status Wget::try_init() {
|
||||
TRY_RESULT(url, parse_url(input_url_));
|
||||
TRY_RESULT(ascii_host, idn_to_ascii(url.host_));
|
||||
url.host_ = std::move(ascii_host);
|
||||
TRY_RESULT_ASSIGN(url.host_, idn_to_ascii(url.host_));
|
||||
|
||||
HttpHeaderCreator hc;
|
||||
if (content_.empty()) {
|
||||
|
@ -40,8 +40,7 @@ Status FileLog::init(string path, int64 rotate_threshold, bool redirect_stderr)
|
||||
} else {
|
||||
path_ = r_path.move_as_ok();
|
||||
}
|
||||
TRY_RESULT(size, fd_.get_size());
|
||||
size_ = size;
|
||||
TRY_RESULT_ASSIGN(size_, fd_.get_size());
|
||||
rotate_threshold_ = rotate_threshold;
|
||||
redirect_stderr_ = redirect_stderr;
|
||||
return Status::OK();
|
||||
|
@ -41,8 +41,7 @@ template <class T>
|
||||
Result<T> read_file_impl(CSlice path, int64 size, int64 offset) {
|
||||
TRY_RESULT(from_file, FileFd::open(path, FileFd::Read));
|
||||
if (size == -1) {
|
||||
TRY_RESULT(file_size, from_file.get_size());
|
||||
size = file_size;
|
||||
TRY_RESULT_ASSIGN(size, from_file.get_size());
|
||||
}
|
||||
if (size < 0) {
|
||||
return Status::Error("Failed to read file: invalid size");
|
||||
|
@ -386,7 +386,7 @@ Status IPAddress::init_host_port(CSlice host, CSlice port, bool prefer_ipv6) {
|
||||
}
|
||||
#endif
|
||||
TRY_RESULT(ascii_host, idn_to_ascii(host));
|
||||
host = ascii_host;
|
||||
host = ascii_host; // assign string to CSlice
|
||||
|
||||
// some getaddrinfo implementations use inet_pton instead of inet_aton and support only decimal-dotted IPv4 form,
|
||||
// and so doesn't recognize 0x12.0x34.0x56.0x78, or 0x12345678, or 0x7f.001 as valid IPv4 addresses
|
||||
|
@ -56,8 +56,7 @@ Status set_temporary_dir(CSlice dir) {
|
||||
input_dir += TD_DIR_SLASH;
|
||||
}
|
||||
TRY_STATUS(mkpath(input_dir, 0750));
|
||||
TRY_RESULT(real_dir, realpath(input_dir));
|
||||
temporary_dir = std::move(real_dir);
|
||||
TRY_RESULT_ASSIGN(temporary_dir, realpath(input_dir));
|
||||
return Status::OK();
|
||||
}
|
||||
|
||||
@ -419,8 +418,7 @@ Result<string> realpath(CSlice slice, bool ignore_access_denied) {
|
||||
return OS_ERROR(PSLICE() << "GetFullPathNameW failed for \"" << slice << '"');
|
||||
}
|
||||
} else {
|
||||
TRY_RESULT(t_res, from_wstring(buf));
|
||||
res = std::move(t_res);
|
||||
TRY_RESULT_ASSIGN(res, from_wstring(buf));
|
||||
}
|
||||
if (res.empty()) {
|
||||
return Status::Error("Empty path");
|
||||
|
Loading…
Reference in New Issue
Block a user