Skip to content

Commit

Permalink
devonfw#877: improved process error message
Browse files Browse the repository at this point in the history
added static getLogLevelFromErrorHandling method to IdeLogLevel
removed Internal error message
replaced check of ProcessErrorHandling with getLogLevelFromErrorHandling
  • Loading branch information
jan-vcapgemini committed Dec 12, 2024
1 parent 75f5043 commit 1c20a31
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
15 changes: 15 additions & 0 deletions cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.devonfw.tools.ide.log;

import java.util.Objects;

import com.devonfw.tools.ide.context.IdeContext;
import com.devonfw.tools.ide.process.ProcessErrorHandling;

/**
* {@link Enum} with the available log-levels.
Expand Down Expand Up @@ -74,4 +77,16 @@ public boolean isCustom() {
return (this == STEP) || (this == INTERACTION) || (this == SUCCESS) || (this == PROCESSABLE);
}

/**
* @param errorHandling the given {@link ProcessErrorHandling}.
* @return matching {@link IdeLogLevel}.
*/
public static IdeLogLevel getLogLevelFromErrorHandling(ProcessErrorHandling errorHandling) {

if (Objects.requireNonNull(errorHandling) == ProcessErrorHandling.LOG_WARNING) {
return IdeLogLevel.WARNING;
}
return IdeLogLevel.ERROR;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -332,18 +332,10 @@ private String addExecutable(String exec, List<String> args) {
private void performLogging(ProcessResult result, int exitCode, String interpreter) {

if (!result.isSuccessful() && (this.errorHandling != ProcessErrorHandling.NONE)) {
IdeLogLevel ideLogLevel;
IdeLogLevel ideLogLevel = IdeLogLevel.getLogLevelFromErrorHandling(this.errorHandling);
;
String message = createCommandMessage(interpreter, "\nfailed with exit code " + exitCode + "!");

if (this.errorHandling == ProcessErrorHandling.LOG_ERROR) {
ideLogLevel = IdeLogLevel.ERROR;
} else if (this.errorHandling == ProcessErrorHandling.LOG_WARNING) {
ideLogLevel = IdeLogLevel.WARNING;
} else {
ideLogLevel = IdeLogLevel.ERROR;
this.context.error("Internal error: Undefined error handling {}", this.errorHandling);
}

context.level(ideLogLevel).log(message);
result.log(ideLogLevel, context);

Expand Down

0 comments on commit 1c20a31

Please sign in to comment.