Skip to content

Conversation

zahidblackduck
Copy link
Collaborator

@zahidblackduck zahidblackduck commented Jul 9, 2025

JIRA Ticket
IDETECT-4728

Issue
When running rapid scans with BOM_COMPARE or BOM_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:

  • Intercept when BAD_REQUEST errors occur during BOM_COMPARE operations
  • Provide specific guidance to users about project version requirements
  • Suggest running a full scan first if the version hasn't been uploaded yet
  • Update the FAILURE_BLACKDUCK_FEATURE_ERROR exit code to reflect the BOM_COMPARE error

Implementation Details

  • Added specific error handling for IntegrationRestException with HTTP 400 status code when BOM_COMPARE or BOM_COMPARE_STRICT modes are used
  • Enhanced error message includes actionable guidance directing users to verify their detect.project.version.name matches an existing project version in Black Duck Hub
  • Refactored error handling logic into separate methods (handleRapidScanException, isBomCompareError, createBomCompareErrorMessage) for better maintainability and testability

Before/After Error Message
Before:

There was a problem trying to `GET {baseHubUrl}/api/developer-scans/{scanId}`, response was 400 Bad Request.

After:

There was a problem trying to `GET {baseHubUrl}/api/developer-scans/{scanId}`, response was 400 Bad Request. BOM_COMPARE mode requires the target project version to exist in Black Duck Hub. Please ensure 'detect.project.version.name' match an existing project version. Consider running a full scan first if the version hasn't been uploaded yet.

N.B: This merge request is meant for detect release 10.7

@zahidblackduck zahidblackduck self-assigned this Jul 9, 2025
@zahidblackduck zahidblackduck marked this pull request as draft July 9, 2025 10:05
Copilot

This comment was marked as outdated.

@zahidblackduck zahidblackduck requested a review from Copilot July 9, 2025 10:24
Copy link
Contributor

@Copilot Copilot AI left a 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, and createBomCompareErrorMessage 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, and createBomCompareErrorMessage 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) {

Comment on lines +755 to +757
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.";
Copy link
Preview

Copilot AI Jul 9, 2025

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.

Suggested change
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));
Copy link
Preview

Copilot AI Jul 9, 2025

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).

Suggested change
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."
Copy link
Contributor

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."

Copy link
Collaborator Author

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.

@zahidblackduck zahidblackduck requested a review from cpottsbd July 10, 2025 12:33
@zahidblackduck zahidblackduck marked this pull request as ready for review July 30, 2025 07:29
@zahidblackduck zahidblackduck merged commit edad8c4 into master Jul 30, 2025
@zahidblackduck zahidblackduck deleted the dev/zahidblackduck/IDETECT-4728 branch August 26, 2025 07:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants