|
5 | 5 | "errors"
|
6 | 6 | "fmt"
|
7 | 7 | "sort"
|
| 8 | + "strings" |
8 | 9 |
|
9 | 10 | "github.com/open-feature/cli/internal/filesystem"
|
10 | 11 | "github.com/open-feature/cli/internal/manifest"
|
@@ -64,7 +65,7 @@ func Load(manifestPath string) (*Flagset, error) {
|
64 | 65 | if err != nil {
|
65 | 66 | return nil, err
|
66 | 67 | } else if len(validationErrors) > 0 {
|
67 |
| - return nil, fmt.Errorf("validation failed: %v", validationErrors) |
| 68 | + return nil, errors.New(FormatValidationError(validationErrors)) |
68 | 69 | }
|
69 | 70 |
|
70 | 71 | var flagset Flagset
|
@@ -132,3 +133,47 @@ func (fs *Flagset) UnmarshalJSON(data []byte) error {
|
132 | 133 |
|
133 | 134 | return nil
|
134 | 135 | }
|
| 136 | +func FormatValidationError(issues []manifest.ValidationError) string { |
| 137 | + var sb strings.Builder |
| 138 | + sb.WriteString("flag manifest validation failed:\n") |
| 139 | + sb.WriteString("+--------------+-------------+------------------+\n") |
| 140 | + sb.WriteString("| flag type | flag path | error messages |\n") |
| 141 | + sb.WriteString("+--------------+-------------+------------------+\n") |
| 142 | + |
| 143 | + // Group messages by flag path |
| 144 | + grouped := make(map[string]struct { |
| 145 | + flagType string |
| 146 | + messages []string |
| 147 | + }) |
| 148 | + |
| 149 | + for _, issue := range issues { |
| 150 | + entry := grouped[issue.Path] |
| 151 | + entry.flagType = issue.Type |
| 152 | + entry.messages = append(entry.messages, issue.Message) |
| 153 | + grouped[issue.Path] = entry |
| 154 | + } |
| 155 | + |
| 156 | + // Sort paths for consistent output |
| 157 | + paths := make([]string, 0, len(grouped)) |
| 158 | + for path := range grouped { |
| 159 | + paths = append(paths, path) |
| 160 | + } |
| 161 | + sort.Strings(paths) |
| 162 | + |
| 163 | + // Format each row |
| 164 | + for _, path := range paths { |
| 165 | + entry := grouped[path] |
| 166 | + sb.WriteString(fmt.Sprintf("- [%-12s] [%-11s]\n \t~ %-16s \n\t\t%s\n \t\t\t%s:\n \t\t\t\t%s\n\t\t\t\t%s \n\n", |
| 167 | + entry.flagType, |
| 168 | + path, |
| 169 | + strings.Join(entry.messages, ", \n\t~ "), |
| 170 | + "Suggestions:", |
| 171 | + path, |
| 172 | + "flagType: boolean", |
| 173 | + "defaultValue: true", |
| 174 | + )) |
| 175 | + } |
| 176 | + |
| 177 | + sb.WriteString("+--------------+-------------+------------------+\n") |
| 178 | + return sb.String() |
| 179 | +} |
0 commit comments