Skip to content

Commit

Permalink
Merge pull request #1336 from blackducksoftware/dev/zahidblackduck/ID…
Browse files Browse the repository at this point in the history
…ETECT-3932

Improve exit code when duplicate project exists
  • Loading branch information
dterrybd authored Jan 23, 2025
2 parents 4877788 + 6b03a68 commit a182471
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public enum ExitCodeType {
FAILURE_ACCURACY_NOT_MET(15, "Detect was unable to meet the required accuracy."),

FAILURE_IMAGE_NOT_AVAILABLE(20, "Image scan attempted but no return data available."),
FAILURE_BLACKDUCK_DUPLICATE_PROJECT_ERROR(21, "Project name already exists, unable to create project."),

FAILURE_COMPONENT_LOCATION_ANALYSIS(25, "Component Location Analysis failed."),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.blackduck.integration.detect.lifecycle;

public class BlackDuckDuplicateProjectException extends OperationException {
private static final long serialVersionUID = 1L;

public BlackDuckDuplicateProjectException(Exception exception) {
super(exception);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.function.Consumer;

import com.blackduck.integration.detect.lifecycle.BlackDuckDuplicateProjectException;
import com.blackduck.integration.detect.workflow.componentlocationanalysis.ComponentLocatorException;
import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -63,6 +64,9 @@ public <T> T wrapped(Operation operation, OperationSupplier<T> supplier, Runnabl
operation.error(e);
}
errorConsumer.accept(e);
if (e.getBlackDuckErrorCode().contains("central.constraint_violation.project_name_duplicate_not_allowed")) {
throw new BlackDuckDuplicateProjectException(e);
}
throw new OperationException(e);
} catch (Exception e) {
// in some cases, the problem is buried in a nested exception
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.blackduck.integration.detect.lifecycle.shutdown;

import com.blackduck.integration.detect.lifecycle.BlackDuckDuplicateProjectException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -52,7 +53,9 @@ public void logException(Exception e) {
}

public ExitCodeType getExitCodeFromException(Exception e) {
if (e instanceof OperationException) {
if (e instanceof BlackDuckDuplicateProjectException) {
return ExitCodeType.FAILURE_BLACKDUCK_DUPLICATE_PROJECT_ERROR;
} else if (e instanceof OperationException) {
return getExitCodeFromException(((OperationException) e).getException());
} else if (e instanceof DetectUserFriendlyException) {
DetectUserFriendlyException friendlyException = (DetectUserFriendlyException) e;
Expand Down

0 comments on commit a182471

Please sign in to comment.