Skip to content

Commit 1c20a31

Browse files
devonfw#877: improved process error message
added static getLogLevelFromErrorHandling method to IdeLogLevel removed Internal error message replaced check of ProcessErrorHandling with getLogLevelFromErrorHandling
1 parent 75f5043 commit 1c20a31

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

cli/src/main/java/com/devonfw/tools/ide/log/IdeLogLevel.java

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.devonfw.tools.ide.log;
22

3+
import java.util.Objects;
4+
35
import com.devonfw.tools.ide.context.IdeContext;
6+
import com.devonfw.tools.ide.process.ProcessErrorHandling;
47

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

80+
/**
81+
* @param errorHandling the given {@link ProcessErrorHandling}.
82+
* @return matching {@link IdeLogLevel}.
83+
*/
84+
public static IdeLogLevel getLogLevelFromErrorHandling(ProcessErrorHandling errorHandling) {
85+
86+
if (Objects.requireNonNull(errorHandling) == ProcessErrorHandling.LOG_WARNING) {
87+
return IdeLogLevel.WARNING;
88+
}
89+
return IdeLogLevel.ERROR;
90+
}
91+
7792
}

cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java

+2-10
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,10 @@ private String addExecutable(String exec, List<String> args) {
332332
private void performLogging(ProcessResult result, int exitCode, String interpreter) {
333333

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

338-
if (this.errorHandling == ProcessErrorHandling.LOG_ERROR) {
339-
ideLogLevel = IdeLogLevel.ERROR;
340-
} else if (this.errorHandling == ProcessErrorHandling.LOG_WARNING) {
341-
ideLogLevel = IdeLogLevel.WARNING;
342-
} else {
343-
ideLogLevel = IdeLogLevel.ERROR;
344-
this.context.error("Internal error: Undefined error handling {}", this.errorHandling);
345-
}
346-
347339
context.level(ideLogLevel).log(message);
348340
result.log(ideLogLevel, context);
349341

0 commit comments

Comments
 (0)