From 7ec4c265146581e3fb75f63cd0c3def6d898c7fe Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 2 Mar 2020 12:52:13 +0300 Subject: [PATCH] Improve error messages. GitOrigin-RevId: 336ef2751e51381c4dd7905ef5b050b691b91e08 --- benchmark/bench_queue.cpp | 1 - td/telegram/CallbackQueriesManager.cpp | 2 +- td/telegram/ContactsManager.cpp | 2 +- td/telegram/InlineQueriesManager.cpp | 4 ++-- td/telegram/Logging.cpp | 2 +- td/telegram/Payments.cpp | 2 +- td/telegram/PrivacyManager.cpp | 6 +++--- td/telegram/SecureStorage.cpp | 4 ++-- td/telegram/SecureValue.cpp | 6 +++--- td/telegram/Td.cpp | 12 ++++++------ td/telegram/net/Proxy.cpp | 4 ++-- 11 files changed, 22 insertions(+), 23 deletions(-) diff --git a/benchmark/bench_queue.cpp b/benchmark/bench_queue.cpp index 7dbe02b8b..d22b1247e 100644 --- a/benchmark/bench_queue.cpp +++ b/benchmark/bench_queue.cpp @@ -43,7 +43,6 @@ //} //} -// TODO: warnings and asserts. There should be no warnings or debug output in production. using qvalue_t = int; // Just for testing, not production diff --git a/td/telegram/CallbackQueriesManager.cpp b/td/telegram/CallbackQueriesManager.cpp index 7455c7124..5369d2df7 100644 --- a/td/telegram/CallbackQueriesManager.cpp +++ b/td/telegram/CallbackQueriesManager.cpp @@ -226,7 +226,7 @@ int64 CallbackQueriesManager::send_callback_query(FullMessageId full_message_id, } if (payload == nullptr) { - promise.set_error(Status::Error(5, "Payload should not be empty")); + promise.set_error(Status::Error(5, "Payload must be non-empty")); return 0; } diff --git a/td/telegram/ContactsManager.cpp b/td/telegram/ContactsManager.cpp index c893bba58..da03a608f 100644 --- a/td/telegram/ContactsManager.cpp +++ b/td/telegram/ContactsManager.cpp @@ -4633,7 +4633,7 @@ std::pair, vector> ContactsManager::change_imported_contac for (auto &contact : contacts) { if (contact == nullptr) { - promise.set_error(Status::Error(400, "Contacts should not be empty")); + promise.set_error(Status::Error(400, "Contacts must be non-empty")); return {}; } } diff --git a/td/telegram/InlineQueriesManager.cpp b/td/telegram/InlineQueriesManager.cpp index a3e9723c4..dfe78d3a4 100644 --- a/td/telegram/InlineQueriesManager.cpp +++ b/td/telegram/InlineQueriesManager.cpp @@ -450,7 +450,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe return promise.set_error(Status::Error(400, "Field \"phone_number\" must contain a valid phone number")); } if (first_name.empty()) { - return promise.set_error(Status::Error(400, "Field \"first_name\" should be non-empty")); + return promise.set_error(Status::Error(400, "Field \"first_name\" must be non-empty")); } title = last_name.empty() ? first_name : first_name + " " + last_name; description = std::move(phone_number); @@ -633,7 +633,7 @@ void InlineQueriesManager::answer_inline_query(int64 inline_query_id, bool is_pe } auto inline_message = r_inline_message.move_as_ok(); if (inline_message->get_id() == telegram_api::inputBotInlineMessageMediaAuto::ID && file_type == FileType::Temp) { - return promise.set_error(Status::Error(400, "Sent message content should be explicitly specified")); + return promise.set_error(Status::Error(400, "Sent message content must be explicitly specified")); } if (duration < 0) { diff --git a/td/telegram/Logging.cpp b/td/telegram/Logging.cpp index 41040be87..ec9d2fedc 100644 --- a/td/telegram/Logging.cpp +++ b/td/telegram/Logging.cpp @@ -59,7 +59,7 @@ Status Logging::set_current_stream(td_api::object_ptr stream) auto file_stream = td_api::move_object_as(stream); auto max_log_file_size = file_stream->max_file_size_; if (max_log_file_size <= 0) { - return Status::Error("Max log file size should be positive"); + return Status::Error("Max log file size must be positive"); } TRY_STATUS(file_log.init(file_stream->path_, max_log_file_size)); diff --git a/td/telegram/Payments.cpp b/td/telegram/Payments.cpp index 569225a4f..b94a5de4d 100644 --- a/td/telegram/Payments.cpp +++ b/td/telegram/Payments.cpp @@ -697,7 +697,7 @@ Result
address_from_json(Slice json) { auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "Address should be an Object"); + return Status::Error(400, "Address must be an Object"); } auto &object = value.get_object(); diff --git a/td/telegram/PrivacyManager.cpp b/td/telegram/PrivacyManager.cpp index 322f6bf5c..fdb9d0268 100644 --- a/td/telegram/PrivacyManager.cpp +++ b/td/telegram/PrivacyManager.cpp @@ -27,7 +27,7 @@ namespace td { Result PrivacyManager::UserPrivacySetting::from_td_api( tl_object_ptr key) { if (!key) { - return Status::Error(5, "UserPrivacySetting should not be empty"); + return Status::Error(5, "UserPrivacySetting must be non-empty"); } return UserPrivacySetting(*key); } @@ -368,12 +368,12 @@ Result PrivacyManager::UserPrivacySetti Result PrivacyManager::UserPrivacySettingRules::from_td_api( tl_object_ptr rules) { if (!rules) { - return Status::Error(5, "UserPrivacySettingRules should not be empty"); + return Status::Error(5, "UserPrivacySettingRules must be non-empty"); } UserPrivacySettingRules result; for (auto &rule : rules->rules_) { if (!rule) { - return Status::Error(5, "UserPrivacySettingRule should not be empty"); + return Status::Error(5, "UserPrivacySettingRule must be non-empty"); } result.rules_.emplace_back(*rule); } diff --git a/td/telegram/SecureStorage.cpp b/td/telegram/SecureStorage.cpp index ce3a6ff03..f1ca6be98 100644 --- a/td/telegram/SecureStorage.cpp +++ b/td/telegram/SecureStorage.cpp @@ -288,7 +288,7 @@ Result Decryptor::append(BufferSlice data) { return BufferSlice(); } if (data.size() % 16 != 0) { - return Status::Error("Part size should be divisible by 16"); + return Status::Error("Part size must be divisible by 16"); } aes_cbc_state_.decrypt(data.as_slice(), data.as_slice()); sha256_state_.feed(data.as_slice()); @@ -330,7 +330,7 @@ Result Encryptor::pread(int64 offset, int64 size) const { return Status::Error("Arbitrary offset is not supported"); } if (size % 16 != 0) { - return Status::Error("Part size should be divisible by 16"); + return Status::Error("Part size must be divisible by 16"); } TRY_RESULT(part, data_view_.pread(offset, size)); aes_cbc_state_.encrypt(part.as_slice(), part.as_slice()); diff --git a/td/telegram/SecureValue.cpp b/td/telegram/SecureValue.cpp index 470b6d900..11aad991e 100644 --- a/td/telegram/SecureValue.cpp +++ b/td/telegram/SecureValue.cpp @@ -796,7 +796,7 @@ static Result> get_personal_details_ auto value = r_value.move_as_ok(); if (value.type() != JsonValue::Type::Object) { - return Status::Error(400, "Personal details should be an Object"); + return Status::Error(400, "Personal details must be an Object"); } auto &object = value.get_object(); @@ -888,7 +888,7 @@ static Result get_identity_document(SecureValueType type, FileManag } } else { if (!need_reverse_side) { - return Status::Error(400, "Document shouldn't have a reverse side"); + return Status::Error(400, "Document can't have a reverse side"); } } @@ -930,7 +930,7 @@ static Result> get_identity_documen auto json_value = r_value.move_as_ok(); if (json_value.type() != JsonValue::Type::Object) { - return Status::Error(400, "Identity document should be an Object"); + return Status::Error(400, "Identity document must be an Object"); } auto &object = json_value.get_object(); diff --git a/td/telegram/Td.cpp b/td/telegram/Td.cpp index 893a5b714..c590c1786 100644 --- a/td/telegram/Td.cpp +++ b/td/telegram/Td.cpp @@ -4759,7 +4759,7 @@ void Td::on_request(uint64 id, td_api::processPushNotification &request) { void Td::on_request(uint64 id, td_api::registerDevice &request) { CHECK_IS_USER(); if (request.device_token_ == nullptr) { - return send_error_raw(id, 400, "Device token should not be empty"); + return send_error_raw(id, 400, "Device token must be non-empty"); } CREATE_REQUEST_PROMISE(); send_closure(device_token_manager_, &DeviceTokenManager::register_device, std::move(request.device_token_), @@ -4795,7 +4795,7 @@ void Td::on_request(uint64 id, const td_api::getAccountTtl &request) { void Td::on_request(uint64 id, const td_api::setAccountTtl &request) { CHECK_IS_USER(); if (request.ttl_ == nullptr) { - return send_error_raw(id, 400, "New account TTL should not be empty"); + return send_error_raw(id, 400, "New account TTL must be non-empty"); } CREATE_OK_REQUEST_PROMISE(); contacts_manager_->set_account_ttl(request.ttl_->days_, std::move(promise)); @@ -4988,7 +4988,7 @@ void Td::on_request(uint64 id, td_api::optimizeStorage &request) { std::vector file_types; for (auto &file_type : request.file_types_) { if (file_type == nullptr) { - return send_error_raw(id, 400, "File type should not be empty"); + return send_error_raw(id, 400, "File type must be non-empty"); } file_types.push_back(from_td_api(*file_type)); @@ -5046,7 +5046,7 @@ void Td::on_request(uint64 id, td_api::resetNetworkStatistics &request) { void Td::on_request(uint64 id, td_api::addNetworkStatistics &request) { if (request.entry_ == nullptr) { - return send_error_raw(id, 400, "Network statistics entry should not be empty"); + return send_error_raw(id, 400, "Network statistics entry must be non-empty"); } NetworkStatsEntry entry; @@ -5121,7 +5121,7 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) { CHECK_IS_USER(); CREATE_REQUEST_PROMISE(); if (request.category_ == nullptr) { - return promise.set_error(Status::Error(400, "Top chat category should not be empty")); + return promise.set_error(Status::Error(400, "Top chat category must be non-empty")); } if (request.limit_ <= 0) { return promise.set_error(Status::Error(400, "Limit must be positive")); @@ -5141,7 +5141,7 @@ void Td::on_request(uint64 id, td_api::getTopChats &request) { void Td::on_request(uint64 id, const td_api::removeTopChat &request) { CHECK_IS_USER(); if (request.category_ == nullptr) { - return send_error_raw(id, 400, "Top chat category should not be empty"); + return send_error_raw(id, 400, "Top chat category must be non-empty"); } DialogId dialog_id(request.chat_id_); diff --git a/td/telegram/net/Proxy.cpp b/td/telegram/net/Proxy.cpp index b20c9478b..0e6e2e09a 100644 --- a/td/telegram/net/Proxy.cpp +++ b/td/telegram/net/Proxy.cpp @@ -12,10 +12,10 @@ namespace td { Result Proxy::from_td_api(string server, int port, td_api::ProxyType *proxy_type) { if (proxy_type == nullptr) { - return Status::Error(400, "Proxy type should not be empty"); + return Status::Error(400, "Proxy type must be non-empty"); } if (server.empty()) { - return Status::Error(400, "Server name can't be empty"); + return Status::Error(400, "Server name must be non-empty"); } if (server.size() > 255) { return Status::Error(400, "Server name is too long");