Skip to content

Commit 6983c4d

Browse files
committed
Remove explicit corrupted file handling
1 parent 19d0c1f commit 6983c4d

6 files changed

Lines changed: 9 additions & 77 deletions

File tree

src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static com.github.stickerifier.stickerify.logger.StructuredLogger.FILE_PATH_LOG_KEY;
66
import static com.github.stickerifier.stickerify.logger.StructuredLogger.ORIGINAL_REQUEST_LOG_KEY;
77
import static com.github.stickerifier.stickerify.logger.StructuredLogger.REQUEST_DETAILS_VALUE;
8-
import static com.github.stickerifier.stickerify.telegram.Answer.CORRUPTED;
98
import static com.github.stickerifier.stickerify.telegram.Answer.ERROR;
109
import static com.github.stickerifier.stickerify.telegram.Answer.FILE_ALREADY_VALID;
1110
import static com.github.stickerifier.stickerify.telegram.Answer.FILE_READY;
@@ -14,7 +13,6 @@
1413
import static java.util.HashSet.newHashSet;
1514
import static java.util.concurrent.Executors.newThreadPerTaskExecutor;
1615

17-
import com.github.stickerifier.stickerify.exception.CorruptedFileException;
1816
import com.github.stickerifier.stickerify.exception.FileOperationException;
1917
import com.github.stickerifier.stickerify.exception.TelegramApiException;
2018
import com.github.stickerifier.stickerify.logger.StructuredLogger;
@@ -184,13 +182,8 @@ private void processFailure(TelegramRequest request, Exception e) {
184182
}
185183
}
186184

187-
if (e instanceof CorruptedFileException) {
188-
LOGGER.at(Level.WARN).log("Unable to reply to the request: the file is corrupted");
189-
answerText(CORRUPTED, request);
190-
} else {
191-
LOGGER.at(Level.ERROR).setCause(e).log("Unable to process file");
192-
answerText(ERROR, request);
193-
}
185+
LOGGER.at(Level.ERROR).setCause(e).log("Unable to process file");
186+
answerText(ERROR, request);
194187
}
195188

196189
private boolean processTelegramFailure(TelegramApiException e, boolean logUnmatchedFailure) {

src/main/java/com/github/stickerifier/stickerify/exception/CorruptedFileException.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import static java.nio.charset.StandardCharsets.ISO_8859_1;
1717
import static java.nio.charset.StandardCharsets.UTF_8;
1818

19-
import com.github.stickerifier.stickerify.exception.CorruptedFileException;
2019
import com.github.stickerifier.stickerify.exception.FileOperationException;
2120
import com.github.stickerifier.stickerify.exception.MediaException;
2221
import com.github.stickerifier.stickerify.exception.ProcessException;
@@ -146,10 +145,10 @@ private static boolean isSupportedVideo(String mimeType) {
146145
*
147146
* @param file the file to check
148147
* @return {@code true} if the file is compliant
149-
* @throws FileOperationException if an error occurred retrieving the size of the file
148+
* @throws MediaException if an error occurred retrieving video information
150149
* @throws InterruptedException if the current thread is interrupted while retrieving file info
151150
*/
152-
private static boolean isVideoCompliant(File file) throws FileOperationException, CorruptedFileException, InterruptedException {
151+
private static boolean isVideoCompliant(File file) throws MediaException, InterruptedException {
153152
var mediaInfo = retrieveMultimediaInfo(file);
154153

155154
var formatInfo = mediaInfo.format();
@@ -180,10 +179,10 @@ private static boolean isVideoCompliant(File file) throws FileOperationException
180179
*
181180
* @param file the video to check
182181
* @return passed-in video's multimedia information
183-
* @throws CorruptedFileException if an error occurred retrieving file information
182+
* @throws MediaException if an error occurred retrieving file information
184183
* @throws InterruptedException if the current thread is interrupted while retrieving file info
185184
*/
186-
static MultimediaInfo retrieveMultimediaInfo(File file) throws CorruptedFileException, InterruptedException {
185+
static MultimediaInfo retrieveMultimediaInfo(File file) throws MediaException, InterruptedException {
187186
var command = new String[] {
188187
"ffprobe",
189188
"-hide_banner",
@@ -199,7 +198,7 @@ static MultimediaInfo retrieveMultimediaInfo(File file) throws CorruptedFileExce
199198

200199
return GSON.fromJson(output, MultimediaInfo.class);
201200
} catch (ProcessException | JsonSyntaxException e) {
202-
throw new CorruptedFileException("The file could not be processed successfully", e);
201+
throw new MediaException("Unable to retrieve media information", e);
203202
}
204203
}
205204

@@ -356,10 +355,10 @@ private static boolean isAnimatedWebp(File file) {
356355
* @param image the image to check
357356
* @param mimeType the MIME type of the file
358357
* @return {@code true} if the file is compliant
359-
* @throws CorruptedFileException if an error occurred retrieving image information
358+
* @throws MediaException if an error occurred retrieving image information
360359
* @throws InterruptedException if the current thread is interrupted while retrieving file info
361360
*/
362-
private static boolean isImageCompliant(File image, String mimeType) throws CorruptedFileException, InterruptedException {
361+
private static boolean isImageCompliant(File image, String mimeType) throws MediaException, InterruptedException {
363362
var mediaInfo = retrieveMultimediaInfo(image);
364363

365364
var formatInfo = mediaInfo.format();

src/main/java/com/github/stickerifier/stickerify/telegram/Answer.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ public enum Answer {
3535
ERROR("""
3636
The file conversion was unsuccessful: only images, gifs, standard and video stickers are supported\\.
3737
38-
If you think it should have worked, please report the issue on [Github](https://github.com/Stickerifier/Stickerify/issues/new/choose)\\.
39-
""", true),
40-
CORRUPTED("""
41-
The conversion was unsuccessful: the media might be corrupted and it cannot be processed\\.
42-
4338
If you think it should have worked, please report the issue on [Github](https://github.com/Stickerifier/Stickerify/issues/new/choose)\\.
4439
""", true),
4540
PRIVACY_POLICY("""

src/test/java/com/github/stickerifier/stickerify/bot/MockResponses.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -295,30 +295,6 @@ public final class MockResponses {
295295
}
296296
""").build();
297297

298-
static final MockResponse CORRUPTED_FILE = new MockResponse.Builder().body("""
299-
{
300-
ok: true,
301-
result: [
302-
{
303-
update_id: 1,
304-
message: {
305-
message_id: 1,
306-
from: {
307-
id: 123456
308-
},
309-
chat: {
310-
id: 1
311-
},
312-
video: {
313-
file_id: "corrupted.mp4",
314-
file_size: 200000
315-
}
316-
}
317-
}
318-
]
319-
}
320-
""").build();
321-
322298
static MockResponse fileInfo(String fileName) {
323299
return new MockResponse.Builder().body("""
324300
{

src/test/java/com/github/stickerifier/stickerify/bot/StickerifyTest.java

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -290,28 +290,4 @@ void documentNotSupported() throws Exception {
290290
assertResponseContainsMessage(sendMessage, Answer.ERROR);
291291
}
292292
}
293-
294-
@Test
295-
void corruptedVideo() throws Exception {
296-
server.enqueue(MockResponses.CORRUPTED_FILE);
297-
server.enqueue(MockResponses.fileInfo("corrupted.mp4"));
298-
server.enqueue(MockResponses.fileDownload("corrupted.mp4"));
299-
300-
try (var _ = runBot()) {
301-
var getUpdates = server.takeRequest();
302-
assertEquals("/api/token/getUpdates", getUpdates.getTarget());
303-
304-
var getFile = server.takeRequest();
305-
assertEquals("/api/token/getFile", getFile.getTarget());
306-
assertNotNull(getFile.getBody());
307-
assertEquals("file_id=corrupted.mp4", getFile.getBody().utf8());
308-
309-
var download = server.takeRequest();
310-
assertEquals("/files/token/corrupted.mp4", download.getTarget());
311-
312-
var sendMessage = server.takeRequest();
313-
assertEquals("/api/token/sendMessage", sendMessage.getTarget());
314-
assertResponseContainsMessage(sendMessage, Answer.CORRUPTED);
315-
}
316-
}
317293
}

0 commit comments

Comments
 (0)