From 499792ff81643de743cbb4d1da7ca7370b47362a Mon Sep 17 00:00:00 2001 From: Riya Garg Date: Thu, 3 Apr 2025 21:01:01 +0530 Subject: [PATCH 1/2] improve error logs for invalid github source url while generating a model Signed-off-by: Riya Garg --- generators/github/error.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/generators/github/error.go b/generators/github/error.go index 5834f6a8..cf7a9480 100644 --- a/generators/github/error.go +++ b/generators/github/error.go @@ -12,9 +12,9 @@ const ( ) func ErrGenerateGitHubPackage(err error, pkgName string) error { - return errors.New(ErrGenerateGitHubPackageCode, errors.Alert, []string{fmt.Sprintf("error generate package for %s", pkgName)}, []string{err.Error()}, []string{"invalid sourceurl provided", "repository might be private"}, []string{"provided sourceURL according to the format", "provide approparite credentials to clone a private repository"}) + return errors.New(ErrGenerateGitHubPackageCode, errors.Alert, []string{fmt.Sprintf("Error generating package for %s", pkgName)}, []string{fmt.Sprintf("Error generating package for %s. %s", pkgName, err.Error())}, []string{"Invalid source URL provided", "Repository might be private"}, []string{"Ensure source URL follows the format: git://[owner]/[repositoryname]/[branch]/[path from the root of repository]", "Make sure the path to CRDs is correct in the URL", "Private repositories aren't supported currently, ensure that provided URL is from a public repository"}) } 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://////"}) + return errors.New(ErrInvalidGitHubSourceURLCode, errors.Alert, []string{"Error parsing the source URL"}, []string{fmt.Sprintf("Error parsing the source URL: %s", err.Error())}, []string{"Source URL provided might be invalid", "Provided repo/version tag does not exist"}, []string{"Ensure source url follows the format: git://[owner]/[repositoryname]/[branch]/[path from the root of repository]"}) } From 697f3f0f11688ba381ccf25b2714a5411ee6fedc Mon Sep 17 00:00:00 2001 From: Riya Garg Date: Wed, 9 Apr 2025 19:17:16 +0530 Subject: [PATCH 2/2] improve error logs for GitHub URL parsing in create model functionality Signed-off-by: Riya Garg --- generators/github/error.go | 14 ++++++++++++-- generators/github/git_repo.go | 2 +- generators/github/package_manager.go | 4 ++-- helpers/component_info.json | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/generators/github/error.go b/generators/github/error.go index cf7a9480..2122f368 100644 --- a/generators/github/error.go +++ b/generators/github/error.go @@ -9,12 +9,22 @@ import ( const ( ErrGenerateGitHubPackageCode = "meshkit-11139" ErrInvalidGitHubSourceURLCode = "meshkit-11140" + ErrInvalidProtocolCode = "meshkit-11311" + ErrFetchingContentfromURLCode = "meshkit-11312" ) func ErrGenerateGitHubPackage(err error, pkgName string) error { - return errors.New(ErrGenerateGitHubPackageCode, errors.Alert, []string{fmt.Sprintf("Error generating package for %s", pkgName)}, []string{fmt.Sprintf("Error generating package for %s. %s", pkgName, err.Error())}, []string{"Invalid source URL provided", "Repository might be private"}, []string{"Ensure source URL follows the format: git://[owner]/[repositoryname]/[branch]/[path from the root of repository]", "Make sure the path to CRDs is correct in the URL", "Private repositories aren't supported currently, ensure that provided URL is from a public repository"}) + return errors.New(ErrGenerateGitHubPackageCode, errors.Alert, []string{fmt.Sprintf("error generate package for %s", pkgName)}, []string{err.Error()}, []string{"invalid sourceurl provided", "repository might be private"}, []string{"provided sourceURL according to the format", "provide approparite credentials to clone a private repository"}) } func ErrInvalidGitHubSourceURL(err error) error { - return errors.New(ErrInvalidGitHubSourceURLCode, errors.Alert, []string{"Error parsing the source URL"}, []string{fmt.Sprintf("Error parsing the source URL: %s", err.Error())}, []string{"Source URL provided might be invalid", "Provided repo/version tag does not exist"}, []string{"Ensure source url follows the format: git://[owner]/[repositoryname]/[branch]/[path from the root of repository]"}) + 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://////"}) +} + +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"}) } diff --git a/generators/github/git_repo.go b/generators/github/git_repo.go index ddf27666..7f5e5746 100644 --- a/generators/github/git_repo.go +++ b/generators/github/git_repo.go @@ -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) diff --git a/generators/github/package_manager.go b/generators/github/package_manager.go index f26fc198..61cc7df6 100644 --- a/generators/github/package_manager.go +++ b/generators/github/package_manager.go @@ -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 } diff --git a/helpers/component_info.json b/helpers/component_info.json index c1debf52..b7bf90ef 100644 --- a/helpers/component_info.json +++ b/helpers/component_info.json @@ -1,5 +1,5 @@ { "name": "meshkit", "type": "library", - "next_error_code": 11311 + "next_error_code": 11313 } \ No newline at end of file