(ch *cmdutil.Helper, result *ValidationResult, outputFormat printer.Format, outputFile string)
| 261 | } |
| 262 | |
| 263 | func outputResult(ch *cmdutil.Helper, result *ValidationResult, outputFormat printer.Format, outputFile string) error { |
| 264 | // Write JSON to file if requested |
| 265 | var jsonData []byte |
| 266 | var err error |
| 267 | if outputFile != "" || outputFormat == printer.FormatJSON { |
| 268 | jsonData, err = json.MarshalIndent(result, "", " ") |
| 269 | if err != nil { |
| 270 | return fmt.Errorf("failed to marshal validation result: %w", err) |
| 271 | } |
| 272 | } |
| 273 | if outputFile != "" { |
| 274 | if err = os.WriteFile(outputFile, jsonData, 0o644); err != nil { |
| 275 | return fmt.Errorf("failed to write output file: %w", err) |
| 276 | } |
| 277 | ch.Printf("Validation results written to output file %s\n", outputFile) |
| 278 | } else { |
| 279 | // Output to console based on format |
| 280 | if outputFormat == printer.FormatJSON { |
| 281 | ch.Println(string(jsonData)) |
| 282 | } else { |
| 283 | // Table format - show parse errors and resources separately |
| 284 | if len(result.ParseErrors) > 0 { |
| 285 | ch.PrintfError("\nParse Errors\n") |
| 286 | ch.PrintData(result.ParseErrors) |
| 287 | ch.Printf("\n") |
| 288 | } |
| 289 | |
| 290 | if len(result.Resources) > 0 { |
| 291 | ch.PrintfSuccess("\nResources\n") |
| 292 | ch.PrintData(result.Resources) |
| 293 | ch.Printf("\n") |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | timeout := false |
| 299 | for _, res := range result.Resources { |
| 300 | if res.Timeout { |
| 301 | timeout = true |
| 302 | break |
| 303 | } |
| 304 | } |
| 305 | if timeout { |
| 306 | return fmt.Errorf("validation timed out for one or more models, check individual resource status to see which; if a model processes full data, consider adding an explicit dev partition or rerun with --model-timeout-seconds to allow more time") |
| 307 | } |
| 308 | |
| 309 | // Print summary in the end |
| 310 | if result.Summary.ParseErrors+result.Summary.ReconcileErrors > 0 { |
| 311 | return fmt.Errorf("validation failed: %d error(s) (%d parse, %d reconcile)", result.Summary.ParseErrors+result.Summary.ReconcileErrors, result.Summary.ParseErrors, result.Summary.ReconcileErrors) |
| 312 | } |
| 313 | |
| 314 | ch.PrintfSuccess("Validation completed successfully\n") |
| 315 | return nil |
| 316 | } |
no test coverage detected