Skip to content

Commit

Permalink
fix: paarse error message
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Jul 3, 2024
1 parent 8141bad commit a01b222
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package testworkflows

import (
"bytes"
"errors"
"fmt"
"os"
"strings"
Expand All @@ -21,6 +22,7 @@ import (

const (
LogTimestampLength = 30 // time.RFC3339Nano without 00:00 timezone
apiErrorMessage = "processing error:"
)

var (
Expand Down Expand Up @@ -72,13 +74,18 @@ func NewRunTestWorkflowCmd() *cobra.Command {
})
if err != nil {
// User friendly Open Source operation error
errs := []error{constants.ErrOpenSourceExecuteOperationIsNotAvailable,
constants.ErrOpenSourceParallelOperationIsNotAvailable,
constants.ErrOpenSourceServicesOperationIsNotAvailable}
for _, e := range errs {
if strings.Contains(err.Error(), e.Error()) {
err = e
break
errMessage := err.Error()
if strings.Contains(errMessage, constants.OpenSourceOperationErrorMessage) {
startp := strings.LastIndex(errMessage, apiErrorMessage)
endp := strings.Index(errMessage, constants.OpenSourceOperationErrorMessage)
if startp != -1 && endp != -1 {
startp += len(apiErrorMessage)
operation := ""
if endp > startp {
operation = strings.TrimSpace(errMessage[startp:endp])
}

err = errors.New(operation + " " + constants.OpenSourceOperationErrorMessage)
}
}
}
Expand Down

0 comments on commit a01b222

Please sign in to comment.