Skip to content

Commit

Permalink
Fix error reporting missing stack trace due to using fmt.Errorf rathe…
Browse files Browse the repository at this point in the history
…r than errors.Errorf (#450)
  • Loading branch information
amitlicht committed Jul 2, 2024
1 parent 84eafa9 commit ad0a9d8
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/operator/api/v1alpha3/otterize_labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1alpha3

import (
"context"
"fmt"
"github.com/otterize/intents-operator/src/shared/errors"
"github.com/otterize/intents-operator/src/shared/serviceidresolver/serviceidentity"
"golang.org/x/exp/maps"
Expand Down Expand Up @@ -102,7 +101,7 @@ func ServiceIdentityToLabelsForWorkloadSelection(ctx context.Context, k8sClient
return nil, false, errors.Wrap(err)
}
if svc.Spec.Selector == nil {
return nil, false, fmt.Errorf("service %s/%s has no selector", svc.Namespace, svc.Name)
return nil, false, errors.Errorf("service %s/%s has no selector", svc.Namespace, svc.Name)
}
return maps.Clone(svc.Spec.Selector), true, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
awsv2 "github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/arn"
"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -116,7 +115,7 @@ func getCredentials(keyPath string, certPath string, roleARN string, account ope
}
output, err := rolesAnywhereClient.CreateSession(&createSessionRequest)
if err != nil {
return awsv2.Credentials{}, fmt.Errorf("failed to create session: %w", err)
return awsv2.Credentials{}, errors.Errorf("failed to create session: %w", err)
}

if len(output.CredentialSet) == 0 {
Expand All @@ -126,7 +125,7 @@ func getCredentials(keyPath string, certPath string, roleARN string, account ope
credentials := output.CredentialSet[0].Credentials
expirationAsTime, err := time.Parse(time.RFC3339, *credentials.Expiration)
if err != nil {
return awsv2.Credentials{}, fmt.Errorf("failed to parse expiration time: %w", err)
return awsv2.Credentials{}, errors.Errorf("failed to parse expiration time: %w", err)
}
finalCredentials := awsv2.Credentials{
AccessKeyID: *credentials.AccessKeyId,
Expand Down
2 changes: 1 addition & 1 deletion src/shared/databaseconfigurator/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (p *PostgresConfigurator) revokeDatabasePermissions(ctx context.Context, us
if err != nil {
pgErr, ok := TranslatePostgresConnectionError(err)
if ok {
return errors.Wrap(fmt.Errorf(pgErr))
return errors.Errorf(pgErr)
}
return errors.Wrap(err)
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/databaseconfigurator/postgres/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TranslatePostgresCommandsError(err error) error {
if pgErr := &(pgconn.PgError{}); errors.As(err, &pgErr) {
// See: https://www.postgresql.org/docs/current/errcodes-appendix.html
if pgErr.Code == "42P01" || pgErr.Code == "3F000" {
return errors.Wrap(fmt.Errorf("bad schema/table name: %s", pgErr.Message))
return errors.Errorf("bad schema/table name: %s", pgErr.Message)
}
if pgErr.Code == "42704" {
return errors.Wrap(ErrUndefinedObject)
Expand Down
3 changes: 2 additions & 1 deletion src/shared/gcpagent/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/clients/generated/apis/k8s/v1alpha1"
otterizev1alpha3 "github.com/otterize/intents-operator/src/operator/api/v1alpha3"
"github.com/otterize/intents-operator/src/shared/agentutils"
"github.com/otterize/intents-operator/src/shared/errors"
"strings"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -66,7 +67,7 @@ func (a *Agent) generateIAMPartialPolicy(namespace string, intentsServiceName st
expression := fmt.Sprintf("resource.name == \"%s\"", intent.Name)
if strings.Contains(intent.Name, "*") {
if strings.Index(intent.Name, "*") != len(intent.Name)-1 {
return nil, fmt.Errorf("wildcard in the middle of the name is not supported: %s", intent.Name)
return nil, errors.Errorf("wildcard in the middle of the name is not supported: %s", intent.Name)
}

cleanName := strings.ReplaceAll(intent.Name, "*", "")
Expand Down

0 comments on commit ad0a9d8

Please sign in to comment.