• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 20007987212

07 Dec 2025 05:44PM UTC coverage: 69.924% (-0.08%) from 70.003%
20007987212

Pull #1641

github

web-flow
Merge 3e3272c89 into 3ccfec4f4
Pull Request #1641: #1640: remove post-install hook from terraform

3924 of 6173 branches covered (63.57%)

Branch coverage included in aggregate %.

10049 of 13810 relevant lines covered (72.77%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.58
cli/src/main/java/com/devonfw/tools/ide/log/IdeLogExceptionDetails.java
1
package com.devonfw.tools.ide.log;
2

3
import java.io.PrintWriter;
4
import java.io.StringWriter;
5
import java.util.Set;
6

7
/**
8
 * {@link Enum} with the available details logged for an {@link Throwable error}.
9
 */
10
public enum IdeLogExceptionDetails {
2✔
11

12
  /** Log the entire stacktrace. */
13
  STACKTRACE(512) {
13✔
14
    @Override
15
    void format(Throwable error, StringWriter sw) {
16

17
      try (PrintWriter pw = new PrintWriter(sw)) {
×
18
        error.printStackTrace(pw);
×
19
      }
20
    }
×
21
  },
22

23
  /** Log only the exception type and message. */
24
  TO_STRING(32) {
13✔
25
    @Override
26
    void format(Throwable error, StringWriter sw) {
27

28
      if (isEmpty(error)) {
×
29
        return;
×
30
      }
31
      sw.append(error.toString());
×
32
    }
×
33
  },
34

35
  /** Log only the message. */
36
  MESSAGE(16) {
13✔
37
    @Override
38
    void format(Throwable error, StringWriter sw) {
39

40
      if (isEmpty(error)) {
×
41
        return;
×
42
      }
43
      String errorMessage = error.getMessage();
×
44
      if ((errorMessage == null) || errorMessage.isBlank()) {
×
45
        if (error instanceof RuntimeException) {
×
46
          return;
×
47
        }
48
        errorMessage = error.getClass().getName();
×
49
      }
50
      sw.append(errorMessage);
×
51
    }
×
52
  },
53

54
  /** Ignore error and only log explicit message. */
55
  NONE(0) {
13✔
56
    @Override
57
    String format(String message, Throwable error) {
58
      return message;
×
59
    }
60

61
    @Override
62
    void format(Throwable error, StringWriter sw) {
63

64
    }
×
65
  };
66

67
  private static final Set<Class<?>> GENERIC_EXCEPTIONS = Set.of(RuntimeException.class, Throwable.class);
5✔
68

69
  private final int capacityOffset;
70

71
  private IdeLogExceptionDetails(int capacityOffset) {
4✔
72

73
    this.capacityOffset = capacityOffset;
3✔
74
  }
1✔
75

76
  /**
77
   * @param message the formatted log message.
78
   * @param error the {@link Throwable} to log.
79
   */
80
  String format(String message, Throwable error) {
81

82
    int capacity = this.capacityOffset;
×
83
    if (message != null) {
×
84
      capacity = capacity + message.length() + 1;
×
85
    }
86
    StringWriter sw = new StringWriter(capacity);
×
87
    if (message != null) {
×
88
      sw.append(message);
×
89
      sw.append('\n');
×
90
    }
91
    format(error, sw);
×
92
    return sw.toString();
×
93
  }
94

95
  abstract void format(Throwable error, StringWriter sw);
96

97
  /**
98
   * @param level the {@link IdeLogLevel} of the {@link IdeSubLogger}.
99
   * @param minLogLevel the minimum {@link IdeLogLevel} (threshold).
100
   * @return the {@link IdeLogExceptionDetails}.
101
   */
102
  static IdeLogExceptionDetails of(IdeLogLevel level, IdeLogLevel minLogLevel) {
103

104
    if ((minLogLevel == IdeLogLevel.TRACE) || (minLogLevel == IdeLogLevel.DEBUG)) {
6!
105
      return STACKTRACE;
2✔
106
    }
107
    return switch (level) {
6✔
108
      case ERROR -> STACKTRACE;
2✔
109
      case WARNING -> TO_STRING;
2✔
110
      default -> MESSAGE;
1✔
111
    };
112
  }
113

114
  private static boolean isEmpty(Throwable error) {
115

116
    String message = error.getMessage();
×
117
    if ((message != null) && !message.isEmpty()) {
×
118
      return false;
×
119
    }
120
    // if we have a generic exception with no message, we assume it is only thrown to get the stacktrace
121
    return GENERIC_EXCEPTIONS.contains(error.getClass());
×
122
  }
123

124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc