diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java index bdd0199c4..3290b8cf0 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java @@ -332,18 +332,9 @@ private String addExecutable(String exec, List args) { private void performLogging(ProcessResult result, int exitCode, String interpreter) { if (!result.isSuccessful() && (this.errorHandling != ProcessErrorHandling.NONE)) { - IdeLogLevel ideLogLevel; + IdeLogLevel ideLogLevel = this.errorHandling.getLogLevel(); 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); diff --git a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java index 640082b82..a46e7f6c0 100644 --- a/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java +++ b/cli/src/main/java/com/devonfw/tools/ide/process/ProcessErrorHandling.java @@ -1,5 +1,7 @@ package com.devonfw.tools.ide.process; +import com.devonfw.tools.ide.log.IdeLogLevel; + /** * {@link Enum} with the available handling if a {@link Process#exitValue() status code} was not {@link ProcessResult#SUCCESS successful}. */ @@ -26,6 +28,15 @@ public enum ProcessErrorHandling { * Throw an exception if the status code was not successful. In this case the {@link ProcessContext#run() run} method will never return an exit code other * than {@link ProcessResult#SUCCESS} as otherwise an exception is thrown preventing the method to return. */ - THROW_ERR + THROW_ERR; + /** + * @return the matching {@link IdeLogLevel}. + */ + public IdeLogLevel getLogLevel() { + if (this.equals(LOG_WARNING)) { + return IdeLogLevel.WARNING; + } + return IdeLogLevel.ERROR; + } }