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

devonfw / IDEasy / 25505184832

07 May 2026 03:23PM UTC coverage: 70.917% (+0.2%) from 70.741%
25505184832

Pull #1858

github

web-flow
Merge f96fc2947 into fd215c395
Pull Request #1858: #1457: Improve CLI error messages with suggestions

4523 of 7036 branches covered (64.28%)

Branch coverage included in aggregate %.

11527 of 15596 relevant lines covered (73.91%)

3.13 hits per line

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

85.96
cli/src/main/java/com/devonfw/tools/ide/validation/ValidationState.java
1
package com.devonfw.tools.ide.validation;
2

3
/**
4
 * Implementation of {@link ValidationResult} as a mutable state that can collect errors dynamically.
5
 */
6
public class ValidationState implements ValidationResult {
7

8
  private final String propertyName;
9

10
  private StringBuilder errorMessage;
11

12
  private String invalidOption;
13

14
  private String invalidArgument;
15

16
  private String invalidArgumentProperty;
17

18

19
  /**
20
   * The default constructor for no property.
21
   */
22
  public ValidationState() {
23
    this(null);
×
24
  }
×
25

26
  /**
27
   * @param propertyName the name of the property to validate.
28
   */
29
  public ValidationState(String propertyName) {
2✔
30
    this.propertyName = propertyName;
3✔
31
  }
1✔
32

33
  @Override
34
  public boolean isValid() {
35
    return (this.errorMessage == null);
7✔
36
  }
37

38
  @Override
39
  public String getErrorMessage() {
40
    if (this.errorMessage == null) {
3✔
41
      return null;
2✔
42
    }
43
    return this.errorMessage.toString();
4✔
44
  }
45

46

47
  /**
48
   * @return the invalid option that caused the error, if applicable, for enhanced error reporting and suggestions. May be {@code null}.
49
   */
50
  public String getInvalidOption() {
51
    if (this.invalidOption == null) {
3!
52
      return null;
×
53
    }
54
    return this.invalidOption;
3✔
55
  }
56

57
  /**
58
   * @param invalidOption the invalid option that caused the error, if applicable, for enhanced error reporting and suggestions.
59
   */
60
  public void addInvalidOption(String invalidOption) {
61
    this.invalidOption = invalidOption;
3✔
62
  }
1✔
63

64
  /**
65
   * @return the invalid argument value that caused the error, if applicable, for enhanced error reporting and suggestions. May be {@code null}.
66
   */
67
  public String getInvalidArgument() {
68
    if (this.invalidArgument == null) {
3!
69
      return null;
×
70
    }
71
    return this.invalidArgument;
3✔
72
  }
73

74
  /**
75
   * @return the property name associated with the invalid argument, if applicable. May be {@code null}.
76
   */
77
  public String getInvalidArgumentProperty() {
78
    if (this.invalidArgumentProperty == null) {
3!
79
      return null;
×
80
    }
81
    return this.invalidArgumentProperty;
3✔
82
  }
83

84
  /**
85
   * @param invalidArgument the invalid argument value that caused the error, if applicable, for enhanced error reporting and suggestions.
86
   * @param propertyName the property name associated with the invalid argument.
87
   */
88
  public void addInvalidArgument(String invalidArgument, String propertyName) {
89
    this.invalidArgument = invalidArgument;
3✔
90
    this.invalidArgumentProperty = propertyName;
3✔
91
  }
1✔
92

93

94
  /**
95
   * @param error the error message to add to this {@link ValidationState}.
96
   */
97
  public void addErrorMessage(String error) {
98
    if (this.errorMessage == null) {
3✔
99
      if (this.propertyName == null) {
3✔
100
        this.errorMessage = new StringBuilder(error.length() + 1);
9✔
101
        this.errorMessage.append('\n');
6✔
102
      } else {
103
        this.errorMessage = new StringBuilder(error.length() + propertyName.length() + 21); // 21 for the static text below
13✔
104
        this.errorMessage.append(String.format("Error in property %s:", propertyName));
13✔
105
        this.errorMessage.append('\n');
6✔
106
      }
107
    } else {
108
      this.errorMessage.append('\n');
5✔
109
    }
110
    this.errorMessage.append(error);
5✔
111
  }
1✔
112

113
  /**
114
   * @param result the {@link ValidationResult} to add to this {@link ValidationState}.
115
   */
116
  public void add(ValidationResult result) {
117
    if (!result.isValid()) {
3✔
118
      if (this.errorMessage == null) {
3✔
119
        this.errorMessage = new StringBuilder(result.getErrorMessage().length());
8✔
120
        this.errorMessage.append(result.getErrorMessage());
7✔
121
      } else {
122
        addErrorMessage(result.getErrorMessage());
4✔
123
      }
124
    }
125
  }
1✔
126
}
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