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

Fix lint: goerr113 #71

Merged
merged 4 commits into from
Feb 1, 2024
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
2 changes: 1 addition & 1 deletion .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ jobs:
uses: kyma-project/eventing-tools/.github/workflows/lint-go-reusable.yml@main
with:
go-version: '1.21'
lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/4bc0e923b67ddb0a028171d8beebc3cb4a211d69/config/lint/.golangci.yaml
lint-config-uri: https://raw.githubusercontent.com/kyma-project/eventing-tools/cf7f3aebaad2d323730a9ab2a76f6cb78f459ee4/config/lint/.golangci.yaml
4 changes: 3 additions & 1 deletion pkg/application/lister.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
emlogger "github.com/kyma-project/eventing-manager/pkg/logger"
)

var ErrFailedToConvertObjectToUnstructured = errors.New("failed to convert runtime object to unstructured")

type Lister struct {
lister cache.GenericLister
}
Expand All @@ -41,7 +43,7 @@ func (l Lister) Get(name string) (*kymaappconnv1alpha1.Application, error) {

u, ok := object.(*unstructured.Unstructured)
if !ok {
return nil, errors.New("failed to convert runtime object to unstructured")
return nil, ErrFailedToConvertObjectToUnstructured
}

a := &kymaappconnv1alpha1.Application{}
Expand Down
4 changes: 3 additions & 1 deletion pkg/cloudevents/builder/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/kyma-project/eventing-manager/pkg/logger"
)

var ErrEventTypeCannotHaveEmptySegments = fmt.Errorf("event type cannot have empty segments after cleaning")

// Perform a compile-time check.
var _ CloudEventBuilder = &GenericBuilder{}

Expand Down Expand Up @@ -57,7 +59,7 @@ func (gb *GenericBuilder) Build(event ceevent.Event) (*ceevent.Event, error) {
// validate if the segments are not empty
segments := strings.Split(finalEventType, ".")
if DoesEmptySegmentsExist(segments) {
return nil, fmt.Errorf("event type cannot have empty segments after cleaning: %s", finalEventType)
return nil, fmt.Errorf("%w: %s", ErrEventTypeCannotHaveEmptySegments, finalEventType)
}
namedLogger.Debugf("using event type: %s", finalEventType)

Expand Down
9 changes: 7 additions & 2 deletions pkg/cloudevents/eventtype/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import (
"github.com/kyma-project/eventing-publisher-proxy/pkg/cloudevents/builder"
)

var ( // Static errors.
the1bit marked this conversation as resolved.
Show resolved Hide resolved
ErrPrefixNotFound = errors.New("prefix not found")
ErrInvalidFormat = errors.New("invalid format")
)

// parse splits the event-type using the given prefix and returns the application name, event and version
// or an error if the event-type format is invalid.
// A valid even-type format should be: prefix.application.event.version or application.event.version
// where event should consist of at least two segments separated by "." (e.g. businessObject.operation).
// Constraint: the application segment in the input event-type should not contain ".".
func parse(eventType, prefix string) (string, string, string, error) {
if !strings.HasPrefix(eventType, prefix) {
return "", "", "", errors.New("prefix not found")
return "", "", "", ErrPrefixNotFound
}

// remove the prefix
Expand All @@ -26,7 +31,7 @@ func parse(eventType, prefix string) (string, string, string, error) {
// (e.g. application.businessObject.operation.version)
parts := strings.Split(eventType, ".")
if len(parts) < 4 || builder.DoesEmptySegmentsExist(parts) {
return "", "", "", errors.New("invalid format")
return "", "", "", ErrInvalidFormat
}

// parse the event-type segments
Expand Down
6 changes: 4 additions & 2 deletions pkg/handler/handler_v1alpha1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
emlogger "github.com/kyma-project/eventing-manager/pkg/logger"
)

var ErrUnableToClean = fmt.Errorf("unable to clean")

func Test_extractCloudEventFromRequest(t *testing.T) {
type args struct {
request *http.Request
Expand Down Expand Up @@ -253,14 +255,14 @@ func TestHandler_publishCloudEvents_v1alpha1(t *testing.T) {
collector: metrics.NewCollector(latency),
eventTypeCleaner: &eventtypetest.CleanerStub{
CleanType: "",
Error: fmt.Errorf("I cannot clean"),
Error: ErrUnableToClean,
},
},
args: args{
request: CreateValidBinaryRequestV1Alpha1(t),
},
wantStatus: 400,
wantBody: []byte("I cannot clean"),
wantBody: []byte("unable to clean"),
the1bit marked this conversation as resolved.
Show resolved Hide resolved
wantTEF: "", // client error will not be recorded as EPP internal error. So no metric will be updated.
},
{
Expand Down
4 changes: 3 additions & 1 deletion pkg/nats/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/nats-io/nats.go"
)

var ErrNATSConnectionNotConnected = fmt.Errorf("NATS connection not connected")

type Opt = nats.Option

//nolint:gochecknoglobals // cloning functions as variables.
Expand All @@ -27,7 +29,7 @@ func Connect(url string, opts ...Opt) (*nats.Conn, error) {
}

if status := connection.Status(); status != nats.CONNECTED {
return nil, fmt.Errorf("NATS connection not connected with status:%v", status)
return nil, fmt.Errorf("%w with status:%v", ErrNATSConnectionNotConnected, status)
}

return connection, err
Expand Down
4 changes: 3 additions & 1 deletion pkg/signals/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"time"
)

var ErrReceivedTerminationSignal = errors.New("received a termination signal")

//nolint:gochecknoglobals // defining channels
var (
// onlyOneSignalHandler to make sure that only one signal handler is registered.
Expand Down Expand Up @@ -70,7 +72,7 @@ func (scc *signalContext) Err() error {
select {
case _, ok := <-scc.Done():
if !ok {
return errors.New("received a termination signal")
return ErrReceivedTerminationSignal
}
default:
}
Expand Down
Loading