Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add message to '.Error()' output for LsError #623

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apis/errors/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"errors"
"fmt"
"reflect"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -30,10 +31,19 @@ type Error struct {

// Error implements the error interface
func (e Error) Error() string {
message := e.lsErr.Message
if e.err != nil {
return e.err.Error()
internalErr := e.err.Error()
if len(e.lsErr.Message) > 0 {
if !strings.HasSuffix(e.lsErr.Message, internalErr) {
// if the developer has not already included the original error in the message, let's add it
message = fmt.Sprintf("%s: %s", e.lsErr.Message, internalErr)
}
} else {
message = internalErr
}
}
return fmt.Sprintf("Op: %s - Reason: %s - Message: %s", e.lsErr.Operation, e.lsErr.Reason, e.lsErr.Message)
return fmt.Sprintf("Op: %s - Reason: %s - Message: %s", e.lsErr.Operation, e.lsErr.Reason, message)
}

// LandscaperError returns the wrapped landscaper error.
Expand Down
11 changes: 10 additions & 1 deletion vendor/github.com/gardener/landscaper/apis/errors/error.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.