-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Divide custom exception into specific ones #261
Conversation
…o suppress-predictable-telegram-issues
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
Dismissed
Show dismissed
Hide dismissed
src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
Dismissed
Show dismissed
Hide dismissed
src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
Dismissed
Show dismissed
Hide dismissed
WalkthroughWalkthroughThe recent changes enhance error handling and code coverage reporting in the Stickerifier application. New exception classes, including Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Bot
participant MediaHelper
participant ExceptionHandler
User->>Bot: Send media file
Bot->>MediaHelper: Process media
MediaHelper->>MediaHelper: Validate media
MediaHelper->>ExceptionHandler: Throw MediaException if invalid
ExceptionHandler-->>Bot: Handle MediaException
Bot-->>User: Notify failure
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range, codebase verification and nitpick comments (3)
src/main/java/com/github/stickerifier/stickerify/exception/MediaOptimizationException.java (1)
1-7
: LGTM!The implementation of the
MediaOptimizationException
class is correct and follows best practices for custom exceptions.Suggestion: Add JavaDoc comments.
Adding JavaDoc comments to the class and its constructor can improve code readability and maintainability.
+/** + * Exception thrown when media optimization fails. + */ public class MediaOptimizationException extends MediaException { + /** + * Constructs a new MediaOptimizationException with the specified detail message. + * + * @param message the detail message + */ public MediaOptimizationException(String message) { super(message); } }src/main/java/com/github/stickerifier/stickerify/exception/TelegramApiException.java (1)
1-10
: LGTM!The implementation of the
TelegramApiException
class is correct and follows best practices for custom exceptions.Suggestion: Add JavaDoc comments.
Adding JavaDoc comments to the class and its constructor can improve code readability and maintainability.
+/** + * Exception thrown when there is an error with the Telegram API. + */ public class TelegramApiException extends BaseException { /** * @see BaseException#BaseException(String, Object...) */ + /** + * Constructs a new TelegramApiException with the specified detail message and parameters. + * + * @param message the detail message + * @param parameters the parameters for the message + */ public TelegramApiException(String message, Object... parameters) { super(message, parameters); } }src/main/java/com/github/stickerifier/stickerify/exception/FileOperationException.java (1)
1-11
: LGTM!The implementation of the
FileOperationException
class is correct and follows best practices for custom exceptions.Suggestion: Add JavaDoc comments.
Adding JavaDoc comments to the class and its constructors can improve code readability and maintainability.
+/** + * Exception thrown when a file operation fails. + */ public class FileOperationException extends MediaException { + /** + * Constructs a new FileOperationException with the specified cause. + * + * @param cause the cause of the exception + */ public FileOperationException(Throwable cause) { super(cause); } + /** + * Constructs a new FileOperationException with the specified detail message and cause. + * + * @param message the detail message + * @param cause the cause of the exception + */ public FileOperationException(String message, Throwable cause) { super(message, cause); } }
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (14)
- build.gradle (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (5 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/BaseException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/FileOperationException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/MediaException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/MediaOptimizationException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/ProcessException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/TelegramApiException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java (16 hunks)
- src/main/java/com/github/stickerifier/stickerify/process/PathLocator.java (2 hunks)
- src/main/java/com/github/stickerifier/stickerify/process/ProcessHelper.java (3 hunks)
- src/main/java/com/github/stickerifier/stickerify/telegram/Answer.java (1 hunks)
- src/test/java/com/github/stickerifier/stickerify/logger/LoggingEvent.java (1 hunks)
- src/test/java/com/github/stickerifier/stickerify/media/MediaHelperTest.java (2 hunks)
Files skipped from review due to trivial changes (2)
- src/main/java/com/github/stickerifier/stickerify/telegram/Answer.java
- src/test/java/com/github/stickerifier/stickerify/logger/LoggingEvent.java
Additional context used
GitHub Check: QDJVM
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
[warning] 172-172: Check Kotlin and Java source code coverage
Method 'processTelegramFailure' coverage is below the threshold 50%src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
[warning] 175-175: Check Kotlin and Java source code coverage
Method 'isFileSizeLowerThan' coverage is below the threshold 50%
[warning] 326-326: Check Kotlin and Java source code coverage
Method 'createTempFile' coverage is below the threshold 50%
Additional comments not posted (34)
src/main/java/com/github/stickerifier/stickerify/exception/ProcessException.java (3)
1-2
: LGTM!The package declaration is correct.
3-6
: LGTM!The class
ProcessException
correctly extendsBaseException
and the constructor withThrowable
cause is implemented correctly.
8-13
: LGTM!The constructor with a parameterized message and JavaDoc comment is implemented correctly.
src/main/java/com/github/stickerifier/stickerify/exception/MediaException.java (5)
1-2
: LGTM!The package declaration is correct.
3-6
: LGTM!The class
MediaException
correctly extendsBaseException
and the constructor with a message is implemented correctly.
8-10
: LGTM!The constructor with
Throwable
cause is implemented correctly.
12-14
: LGTM!The constructor with a message and
Throwable
cause is implemented correctly.
16-21
: LGTM!The constructor with a parameterized message and JavaDoc comment is implemented correctly.
src/main/java/com/github/stickerifier/stickerify/exception/BaseException.java (4)
1-2
: LGTM!The package declaration is correct.
3-4
: LGTM!The import statement for
MessageFormatter
is correct.
5-8
: LGTM!The class
BaseException
correctly extendsException
and the constructor withThrowable
cause is implemented correctly.
10-20
: LGTM!The constructor with a parameterized message and JavaDoc comment is implemented correctly. The usage of
MessageFormatter.basicArrayFormat
is appropriate.src/main/java/com/github/stickerifier/stickerify/process/PathLocator.java (1)
6-6
: LGTM! Verify the usage ofProcessException
.The import statement change aligns with the PR objectives. Ensure that
ProcessException
is correctly used throughout the codebase.Verification successful
The usage of
ProcessException
is correctly implemented throughout the codebase.The import statement change aligns with the PR objectives. The
ProcessException
is used consistently and appropriately in the following files:
ProcessHelper.java
PathLocator.java
MediaHelper.java
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `ProcessException` in the codebase. # Test: Search for the usage of `ProcessException`. Expect: Correct usage in all instances. rg --type java -A 5 $'ProcessException'Length of output: 6856
build.gradle (1)
51-51
: LGTM! Verify the exclusion pattern.The exclusion pattern addition aligns with the PR objectives. Ensure that the exclusion pattern is correctly applied in the coverage report.
Verification successful
Verified: The exclusion pattern has been correctly applied.
The exclusion pattern
**/stickerify/exception/**
is correctly included in thebuild.gradle
file as part of the JaCoCo configuration.
build.gradle:51
:**/stickerify/exception/**
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the exclusion pattern in the JaCoCo configuration. # Test: Search for the exclusion pattern in the `build.gradle` file. Expect: Correct exclusion pattern. rg --type gradle -A 5 $'**/stickerify/exception/**'Length of output: 154
Script:
#!/bin/bash # Description: Verify the exclusion pattern in the JaCoCo configuration. # Test: Search for the exclusion pattern in the `build.gradle` file. Expect: Correct exclusion pattern. rg --type gradle -F '**/stickerify/exception/**' -A 5Length of output: 424
src/main/java/com/github/stickerifier/stickerify/process/ProcessHelper.java (2)
6-6
: LGTM! Verify the usage ofProcessException
.The import statement change aligns with the PR objectives. Ensure that
ProcessException
is correctly used throughout the codebase.Verification successful
The usage of
ProcessException
is correctly implemented throughout the codebase.The import and usage of
ProcessException
inProcessHelper.java
,PathLocator.java
, andMediaHelper.java
are consistent with the intended exception handling improvements.
ProcessHelper.java
:ProcessException
is thrown in theexecuteCommand
method.PathLocator.java
:ProcessException
is caught and logged.MediaHelper.java
:ProcessException
is caught and rethrown asMediaException
.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `ProcessException` in the codebase. # Test: Search for the usage of `ProcessException`. Expect: Correct usage in all instances. rg --type java -A 5 $'ProcessException'Length of output: 6856
25-25
: LGTM! Verify the usage ofProcessException
.The method signature change aligns with the PR objectives. Ensure that
ProcessException
is correctly used throughout the codebase.Verification successful
Verified the usage of
ProcessException
.The
ProcessException
is used correctly throughout the codebase in the following files:
src/main/java/com/github/stickerifier/stickerify/process/ProcessHelper.java
src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
src/main/java/com/github/stickerifier/stickerify/process/PathLocator.java
The exception handling aligns with the intended purpose of enhancing exception handling in the project.
Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `ProcessException` in the codebase. # Test: Search for the usage of `ProcessException`. Expect: Correct usage in all instances. rg --type java -A 5 $'ProcessException'Length of output: 6856
src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (5)
137-137
: LGTM! The changes broaden the scope of error management.The catch block now handles multiple exception types (
TelegramApiException
andMediaException
), enhancing error management during file answering operations.
Line range hint
144-154
: LGTM! The changes improve error handling.The method signature now includes
FileOperationException
in its throws clause, reflecting an improved approach to error handling when retrieving files from the Telegram API.
158-163
: LGTM! The changes enhance the robustness of error processing.The method now accepts a more general
BaseException
instead of justTelegramApiException
, allowing for unified handling of different exception types.
172-182
: LGTM! The new method improves code clarity and maintainability.The newly introduced method
processTelegramFailure
encapsulates the logic for processing Telegram-related failures, enhancing code clarity and maintainability.Tools
GitHub Check: QDJVM
[warning] 172-172: Check Kotlin and Java source code coverage
Method 'processTelegramFailure' coverage is below the threshold 50%
194-204
: LGTM! The changes enhance message formatting flexibility.The method now includes
LinkPreviewOptions
, allowing for more nuanced control over link previews in messages sent via the Telegram bot.src/test/java/com/github/stickerifier/stickerify/media/MediaHelperTest.java (2)
239-239
: LGTM! The changes reflect the updated exception handling.The test case now asserts
MediaException
instead ofTelegramApiException
, reflecting a shift in the expected exception type.
246-246
: LGTM! The changes reflect the updated exception handling.The test case now asserts
MediaException
instead ofTelegramApiException
, reflecting a shift in the expected exception type.src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java (11)
Line range hint
68-93
: LGTM! The changes improve error handling.The method now throws
MediaException
instead ofTelegramApiException
, indicating a more focused error handling approach for media-related issues.
Line range hint
125-154
: LGTM! The changes improve error handling.The method now throws
FileOperationException
instead ofTelegramApiException
, reflecting a shift towards more granular exception types that are relevant to file operations.
175-179
: LGTM! The changes improve error handling.The method now throws
FileOperationException
instead ofTelegramApiException
, reflecting a shift towards more granular exception types that are relevant to file operations.Tools
GitHub Check: QDJVM
[warning] 175-175: Check Kotlin and Java source code coverage
Method 'isFileSizeLowerThan' coverage is below the threshold 50%
191-197
: LGTM! The changes improve error handling.The method now throws
FileOperationException
instead ofTelegramApiException
, reflecting a shift towards more granular exception types that are relevant to file operations.
Line range hint
220-291
: LGTM! The changes improve error handling.The method now throws
MediaException
instead ofTelegramApiException
, aligning with the new error handling strategy.
308-308
: LGTM! The changes improve error handling.The method now throws
MediaException
instead ofTelegramApiException
, aligning with the new error handling strategy.
326-330
: LGTM! The changes improve error handling.The method now throws
FileOperationException
instead ofTelegramApiException
, reflecting a shift towards more granular exception types that are relevant to file operations.Tools
GitHub Check: QDJVM
[warning] 326-326: Check Kotlin and Java source code coverage
Method 'createTempFile' coverage is below the threshold 50%
342-342
: LGTM! The changes improve error handling.The method now throws
MediaException
instead ofTelegramApiException
, aligning with the new error handling strategy.
361-365
: LGTM! The changes improve error handling.The method now throws
MediaException
instead ofTelegramApiException
, aligning with the new error handling strategy.
378-378
: LGTM! The changes improve error handling.The method now throws
FileOperationException
instead ofTelegramApiException
, reflecting a shift towards more granular exception types that are relevant to file operations.
Line range hint
400-422
: LGTM! The changes improve error handling.The method now throws
MediaException
instead ofTelegramApiException
, aligning with the new error handling strategy.
…o suppress-predictable-telegram-issues
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java (16 hunks)
- src/main/java/com/github/stickerifier/stickerify/process/ProcessHelper.java (3 hunks)
Files skipped from review as they are similar to previous changes (2)
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
- src/main/java/com/github/stickerifier/stickerify/process/ProcessHelper.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (6 hunks)
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java (16 hunks)
Files skipped from review as they are similar to previous changes (2)
- src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java (6 hunks)
- src/main/java/com/github/stickerifier/stickerify/exception/CorruptedVideoException.java (1 hunks)
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java (16 hunks)
Files skipped from review as they are similar to previous changes (2)
- src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java
- src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java
Additional comments not posted (1)
src/main/java/com/github/stickerifier/stickerify/exception/CorruptedVideoException.java (1)
1-7
: Well-structured custom exception class.The
CorruptedVideoException
class is well-defined and extendsMediaException
, providing a constructor for detailed error messaging. This aligns with the PR's objective of enhancing exception handling by introducing specific exception types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Along with a major exception overhaul, this pull request also removes the use of the recently deprecated method
disableWebPagePreview
.Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Style