Skip to content

Improve error logs related to invalid source url in model generation #709

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions generators/github/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
const (
ErrGenerateGitHubPackageCode = "meshkit-11139"
ErrInvalidGitHubSourceURLCode = "meshkit-11140"
ErrInvalidProtocolCode = "meshkit-11311"
ErrFetchingContentfromURLCode = "meshkit-11312"
)

func ErrGenerateGitHubPackage(err error, pkgName string) error {
Expand All @@ -18,3 +20,11 @@ func ErrGenerateGitHubPackage(err error, pkgName string) error {
func ErrInvalidGitHubSourceURL(err error) error {
return errors.New(ErrInvalidGitHubSourceURLCode, errors.Alert, []string{}, []string{err.Error()}, []string{"sourceURL provided might be invalid", "provided repo/version tag does not exist"}, []string{"ensure source url follows the format: git://<owner>/<repositoryname>/<branch>/<version>/<path from the root of repository>"})
}

func ErrInvalidProtocol(err error, pkgName string, protocol string) error {
return errors.New(ErrInvalidProtocolCode, errors.Alert, []string{fmt.Sprintf("Unsupported protocol used in source URL for %s", pkgName)}, []string{fmt.Sprintf("Unsupported protocol used in source URL for %s. Error details: %s", pkgName, err.Error())}, []string{fmt.Sprintf("The URL scheme '%s' used in %s is not supported", protocol, pkgName)}, []string{"The 'git' protocol is supported for GitHub repositories.", "Refer to documentation for more details: https://docs.meshery.io/project/contributing/contributing-models#instructions-for-creating-a-new-model"})
}

func ErrFetchingContentfromURL(err error) error {
return errors.New(ErrFetchingContentfromURLCode, errors.Alert, []string{"Error fetching contents from provided source URL"}, []string{fmt.Sprintf("Error fetching contents from provided link to repository. Error details: %s", err.Error())}, []string{"Provided source URL might not follow a valid Git protocol URL format.", "It might have components like `/blob/` or `/tree/`, which are used for viewing files or folders in the browser, not for accessing the repository itself.", "The manifests are in compressed formats like .tgz or .zip"}, []string{"Ensure source URL follows the correct Git protocol format: git://[owner]/[repositoryname]/[branch]/[version]/[path-from-the-root-of-repository]", "Ensure that manifests are in an uncompressed form", "Refer to documentation for more details: https://docs.meshery.io/project/contributing/contributing-models#instructions-for-creating-a-new-model"})
}
2 changes: 1 addition & 1 deletion generators/github/git_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (gr GitRepo) GetContent() (models.Package, error) {

versions, err := utils.GetLatestReleaseTagsSorted(owner, repo)
if err != nil {
return nil, ErrInvalidGitHubSourceURL(err)
return nil, err
}
version := versions[len(versions)-1]
dirPath := filepath.Join(os.TempDir(), owner, repo, branch)
Expand Down
4 changes: 2 additions & 2 deletions generators/github/package_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ func (ghpm GitHubPackageManager) GetPackage() (models.Package, error) {

downloader := NewDownloaderForScheme(protocol, url, ghpm.PackageName)
if downloader == nil {
return nil, ErrGenerateGitHubPackage(err, ghpm.PackageName)
return nil, ErrInvalidProtocol(err, ghpm.PackageName, protocol)
}
ghPackage, err := downloader.GetContent()
if err != nil {
return nil, ErrGenerateGitHubPackage(err, ghpm.PackageName)
return nil, ErrFetchingContentfromURL(err)
}
return ghPackage, nil
}
Loading