Complete comparison failure summaries
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/app"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/comparison"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/promptexec"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/report"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/weatherdata"
|
||||
@@ -216,29 +217,50 @@ func comparisonSummaryStatus(result *app.ComparisonResult, err error) string {
|
||||
}
|
||||
|
||||
func safeComparisonSummaryError(err error) *comparison.SafeError {
|
||||
message := "comparison did not complete"
|
||||
if aggregate, ok := comparisonAggregateErrorMessage(err.Error()); ok {
|
||||
message = aggregate
|
||||
} else if errors.Is(err, context.DeadlineExceeded) {
|
||||
message = "comparison deadline exceeded"
|
||||
} else if errors.Is(err, context.Canceled) {
|
||||
message = "comparison canceled"
|
||||
if aggregate, ok := comparisonAggregateErrorMessage(err); ok {
|
||||
safe := comparison.NewSafeError("application", aggregate)
|
||||
return &safe
|
||||
}
|
||||
safe := comparison.NewSafeError("application", message)
|
||||
var cleanupErr *comparison.PublicationCleanupError
|
||||
if errors.As(err, &cleanupErr) {
|
||||
safe := comparison.NewSafeError("publication_cleanup", "comparison published but cleanup did not complete")
|
||||
return &safe
|
||||
}
|
||||
var destinationErr *comparison.DestinationError
|
||||
if errors.As(err, &destinationErr) {
|
||||
safe := comparison.NewSafeError("destination_"+string(destinationErr.Kind), "comparison destination preflight failed")
|
||||
return &safe
|
||||
}
|
||||
if category := promptexec.CategoryOf(err); category != "" {
|
||||
safe := comparison.NewSafeError(string(category), "comparison prompt operation failed")
|
||||
return &safe
|
||||
}
|
||||
if errors.Is(err, context.DeadlineExceeded) {
|
||||
safe := comparison.NewSafeError("deadline_exceeded", "comparison deadline exceeded")
|
||||
return &safe
|
||||
}
|
||||
if errors.Is(err, context.Canceled) {
|
||||
safe := comparison.NewSafeError("canceled", "comparison canceled")
|
||||
return &safe
|
||||
}
|
||||
safe := comparison.NewSafeError("application", "comparison did not complete")
|
||||
return &safe
|
||||
}
|
||||
|
||||
func comparisonAggregateErrorMessage(value string) (string, bool) {
|
||||
func comparisonAggregateErrorMessage(err error) (string, bool) {
|
||||
const prefix = "comparison completed with "
|
||||
const suffix = " failed profiles"
|
||||
if !strings.HasPrefix(value, prefix) || !strings.HasSuffix(value, suffix) {
|
||||
return "", false
|
||||
for candidate := err; candidate != nil; candidate = errors.Unwrap(candidate) {
|
||||
value := candidate.Error()
|
||||
if !strings.HasPrefix(value, prefix) || !strings.HasSuffix(value, suffix) {
|
||||
continue
|
||||
}
|
||||
count, parseErr := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(value, prefix), suffix))
|
||||
if parseErr == nil && count > 0 {
|
||||
return fmt.Sprintf("comparison completed with %d failed profiles", count), true
|
||||
}
|
||||
}
|
||||
count, err := strconv.Atoi(strings.TrimSuffix(strings.TrimPrefix(value, prefix), suffix))
|
||||
if err != nil || count < 1 {
|
||||
return "", false
|
||||
}
|
||||
return fmt.Sprintf("comparison completed with %d failed profiles", count), true
|
||||
return "", false
|
||||
}
|
||||
|
||||
func batchSummaryStatus(result *app.BatchResult) string {
|
||||
|
||||
Reference in New Issue
Block a user