Skip to content

Commit

Permalink
Return user friendly error when package doesn't exist
Browse files Browse the repository at this point in the history
  • Loading branch information
rcmadhankumar committed Sep 13, 2023
1 parent 786f84b commit f8cc005
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/apiserver/registry/datapackaging/package_storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/base32"
"fmt"
"regexp"
"strings"

internalpkgingv1alpha1 "github.com/vmware-tanzu/carvel-kapp-controller/pkg/apis/internalpackaging/v1alpha1"
Expand Down Expand Up @@ -152,7 +153,25 @@ func (t PackageTranslator) ToExternalWatcher(intObjWatcher watch.Interface, fiel
}

func (t PackageTranslator) ToExternalError(err error) error {
// TODO: implement
if errors.IsNotFound(err) {
errStr := err.Error()
regEx := `^internalpackages\.internal\.packaging\.carvel\.dev "(?P<internalPackageName>[a-z0-9]*)" not found$`
re := regexp.MustCompile(regEx)
match := re.FindStringSubmatch(errStr)
internalPackageName := ""
for i, name := range re.SubexpNames() {
if i != 0 && name == "internalPackageName" {
internalPackageName = match[i]
}
}

packageName, err := t.ToExternalName(internalPackageName)
if err != nil {
return err
}
return errors.NewNotFound(datapkgingv1alpha1.Resource("package"), packageName)
}

return err
}

Expand Down

0 comments on commit f8cc005

Please sign in to comment.