-
Notifications
You must be signed in to change notification settings - Fork 80
Enhance error message for BOM_COMPARE mode failures in rapid scan #1467
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
Conversation
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.
Pull Request Overview
Enhance error message for BOM_COMPARE mode failures in rapid scans by intercepting 400 Bad Request errors and providing actionable guidance.
- Wrap rapid scan API call in a try-catch to handle
IntegrationRestException
- Introduce
handleRapidScanException
,isBomCompareError
, andcreateBomCompareErrorMessage
methods for targeted error logic - Augment user-facing error message with instructions on project version existence and running full scans
Comments suppressed due to low confidence (2)
src/main/java/com/blackduck/integration/detect/lifecycle/run/operation/OperationRunner.java:733
- New error handling logic in
handleRapidScanException
,isBomCompareError
, andcreateBomCompareErrorMessage
would benefit from dedicated unit tests to verify the enhanced error message and branch behavior.
private OperationException handleRapidScanException(IntegrationRestException e) {
src/main/java/com/blackduck/integration/detect/lifecycle/run/operation/OperationRunner.java:748
- The method assumes
rapidCompareMode
is non-null, which could lead to a NullPointerException. Consider adding a null check before comparing.
private boolean isBomCompareError(IntegrationRestException e, RapidCompareMode rapidCompareMode) {
return originalMessage + " BOM_COMPARE mode requires the target project version to exist in Black Duck Hub. " + | ||
"Please ensure 'detect.project.version.name' matches an existing project version. " + | ||
"Consider running a full scan first if the version hasn't been uploaded yet."; |
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.
[nitpick] The string concatenation for the enhanced error message is lengthy; consider using a text block (Java 15+) or String.format
for improved readability and maintainability.
return originalMessage + " BOM_COMPARE mode requires the target project version to exist in Black Duck Hub. " + | |
"Please ensure 'detect.project.version.name' matches an existing project version. " + | |
"Consider running a full scan first if the version hasn't been uploaded yet."; | |
return """ | |
%s BOM_COMPARE mode requires the target project version to exist in Black Duck Hub. | |
Please ensure 'detect.project.version.name' matches an existing project version. | |
Consider running a full scan first if the version hasn't been uploaded yet. | |
""".formatted(originalMessage); |
Copilot uses AI. Check for mistakes.
logger.error("Rapid scan failed. {}", enhancedMessage); | ||
return new OperationException(new IntegrationRestException( | ||
e.getHttpMethod(), e.getHttpUrl(), e.getHttpStatusCode(), | ||
e.getHttpStatusMessage(), e.getHttpResponseContent(), enhancedMessage)); |
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.
Wrapping the original exception loses the original stack trace. Consider passing the original e
as the cause to preserve debugging context, e.g., new OperationException(new IntegrationRestException(...), e)
.
e.getHttpStatusMessage(), e.getHttpResponseContent(), enhancedMessage)); | |
e.getHttpStatusMessage(), e.getHttpResponseContent(), enhancedMessage, e)); |
Copilot uses AI. Check for mistakes.
@@ -16,7 +16,7 @@ public enum ExitCodeType { | |||
), | |||
FAILURE_BLACKDUCK_FEATURE_ERROR( | |||
11, | |||
"Detect encountered an error while attempting an operation on Black Duck. Ensure that your Black Duck version is compatible with this version of Detect, and that your Black Duck user account has the required roles." | |||
"Detect encountered an error while attempting an operation on Black Duck. Ensure that your Black Duck version is compatible with this version of Detect, and that your Black Duck user account has the required roles, and the project version exists in Black Duck when using BOM_COMPARE mode in a rapid scan." |
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.
Suggest tweak:
"While trying to perform an operation on Black Duck SCA, Detect encountered an error. Ensure that your Black Duck SCA version is compatible with this version of Detect, your Black Duck user account has the required roles, and the project version exists in Black Duck when using BOM_COMPARE mode in a rapid scan."
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.
Thanks for the suggestion. I made a small tweak to start the sentence with "Detect" to stay consistent with the style used in the other exit codes.
JIRA Ticket
IDETECT-4728
Issue
When running rapid scans with
BOM_COMPARE
orBOM_COMPARE_STRICT
modes, users receive a generic "400 Bad Request" error message without clear guidance on how to resolve the issue. The root cause is typically that the target project version doesn't exist in Black Duck Hub, but this wasn't communicated effectively to users.Proposed Fix
Enhanced error handling in the
waitForRapidResults
method to:FAILURE_BLACKDUCK_FEATURE_ERROR
exit code to reflect theBOM_COMPARE
errorImplementation Details
IntegrationRestException
with HTTP 400 status code whenBOM_COMPARE
orBOM_COMPARE_STRICT
modes are useddetect.project.version.name
matches an existing project version in Black Duck HubhandleRapidScanException
,isBomCompareError
,createBomCompareErrorMessage
) for better maintainability and testabilityBefore/After Error Message
Before:
After:
N.B: This merge request is meant for detect release 10.7