Skip to content

Commit

Permalink
fix: handle case where error cause or details are not available
Browse files Browse the repository at this point in the history
Signed-off-by: Souvik Kar Mahapatra <souvikat001@gmail.com>
  • Loading branch information
souvikinator committed Jan 24, 2025
1 parent 7d3da8f commit ba9bd82
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,33 +841,27 @@ func ParseKubeStatusErr(err *kubeerror.StatusError) (shortDescription, longDescr

status := err.Status()

// Create base description including status code
baseDesc := fmt.Sprintf("[Status Code: %d] %s", status.Code, status.Reason)
if status.Details != nil {
baseDesc = fmt.Sprintf("%s: %s '%s'", baseDesc, status.Details.Kind, status.Details.Name)
}
shortDescription = append(shortDescription, baseDesc)

// Add the main error message
longDescription = append(longDescription, status.Message)
// Add the high-level error message with status code to longDescription
longDescription = append(longDescription, fmt.Sprintf("[Status Code: %d] %s", status.Code, status.Message))

// Add reason-based guidance
pc, rem := handleStatusReason(status.Reason)
probableCause = append(probableCause, pc)
remedy = append(remedy, rem)

// Process detailed causes if available
// Add specific field validation errors
if status.Details != nil && len(status.Details.Causes) > 0 {
for _, cause := range status.Details.Causes {
// Add detailed cause description
longDescription = append(longDescription,
fmt.Sprintf("Field '%s': %s", cause.Field, cause.Message))
longDescription = append(longDescription, fmt.Sprintf("Field '%s': %s", cause.Field, cause.Message))

// Get cause-specific messages
pc, rem := handleStatusCause(cause, status.Details.Kind)
probableCause = append(probableCause, pc)
remedy = append(remedy, rem)
}
} else {
// If no specific causes are provided, add the general reason-based guidance
pc, rem := handleStatusReason(status.Reason)
probableCause = append(probableCause, pc)
remedy = append(remedy, rem)
}

return
Expand Down

0 comments on commit ba9bd82

Please sign in to comment.