Skip to content

Commit 84ce382

Browse files
committed
Improve error messages.
1 parent cdfc52b commit 84ce382

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

‎td/telegram/files/FileLoaderUtils.cpp

+13-11
Original file line numberDiff line numberDiff line change
@@ -318,33 +318,35 @@ Result<FullLocalLocationInfo> check_full_local_location(FullLocalLocationInfo lo
318318
} else if (!are_modification_times_equal(location.mtime_nsec_, stat.mtime_nsec_)) {
319319
VLOG(file_loader) << "File \"" << location.path_ << "\" was modified: old mtime = " << location.mtime_nsec_
320320
<< ", new mtime = " << stat.mtime_nsec_;
321-
return Status::Error(400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" was modified");
321+
return Status::Error(400, "File was modified");
322322
}
323323
if (skip_file_size_checks) {
324324
return std::move(local_info);
325325
}
326326

327-
auto get_file_size_error = [&](Slice reason) {
328-
return Status::Error(400, PSLICE() << "File \"" << utf8_encode(location.path_) << "\" of size " << size
329-
<< " bytes is too big" << reason);
327+
auto get_file_size_error = [&](Slice reason, int64 max_size) {
328+
return Status::Error(400, PSLICE() << "File of size " << size << " bytes is too big" << reason
329+
<< "; the maximum size is " << max_size << " bytes");
330330
};
331331
if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) &&
332332
size > MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map") &&
333333
!begins_with(PathView(location.path_).file_name(), "Album cover for ")) {
334-
return get_file_size_error(" for a thumbnail");
334+
return get_file_size_error(" for a thumbnail", MAX_THUMBNAIL_SIZE);
335335
}
336336
if (size > MAX_FILE_SIZE) {
337-
return get_file_size_error("");
337+
return get_file_size_error("", MAX_FILE_SIZE);
338338
}
339339
if (get_file_type_class(location.file_type_) == FileTypeClass::Photo && size > MAX_PHOTO_SIZE) {
340-
return get_file_size_error(" for a photo");
340+
return get_file_size_error(" for a photo", MAX_PHOTO_SIZE);
341341
}
342-
if ((location.file_type_ == FileType::VideoNote || location.file_type_ == FileType::SelfDestructingVideoNote) &&
343-
size > G()->get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX)) {
344-
return get_file_size_error(" for a video note");
342+
if (location.file_type_ == FileType::VideoNote || location.file_type_ == FileType::SelfDestructingVideoNote) {
343+
auto max_size = G()->get_option_integer("video_note_size_max", DEFAULT_VIDEO_NOTE_SIZE_MAX);
344+
if (size > max_size) {
345+
return get_file_size_error(" for a video note", max_size);
346+
}
345347
}
346348
if (location.file_type_ == FileType::VideoStory && size > MAX_VIDEO_STORY_SIZE) {
347-
return get_file_size_error(" for a video story");
349+
return get_file_size_error(" for a video story", MAX_VIDEO_STORY_SIZE);
348350
}
349351
return std::move(local_info);
350352
}

0 commit comments

Comments
 (0)