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

Do not swallow errors in getRepoPath #685

Merged
merged 2 commits into from Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/tfgen/docs.go
Expand Up @@ -34,6 +34,7 @@ import (
"golang.org/x/text/language"

"github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tf2pulumi/gen/python"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag"
"github.com/pulumi/pulumi/sdk/v3/go/common/tokens"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/spf13/afero"
Expand Down Expand Up @@ -156,7 +157,8 @@ func getRepoPath(gitHost string, org string, provider string, version string) (s
command.Dir = curWd
output, err := command.CombinedOutput()
if err != nil {
return "", fmt.Errorf("error running 'go mod download -json' for module: %w", err)
msg := "error running 'go mod download -json' in %q dir for module: %w\n\nOutput: %s"
return "", fmt.Errorf(msg, curWd, err, output)
}

target := struct {
Expand All @@ -178,7 +180,8 @@ func getRepoPath(gitHost string, org string, provider string, version string) (s
return target.Dir, nil
}

func getMarkdownDetails(org string, provider string, resourcePrefix string, kind DocKind, rawname string,
func getMarkdownDetails(sink diag.Sink, org string, provider string,
resourcePrefix string, kind DocKind, rawname string,
info tfbridge.ResourceOrDataSourceInfo, providerModuleVersion string, githost string) ([]byte, string, bool) {

var docinfo *tfbridge.DocInfo
Expand All @@ -191,6 +194,8 @@ func getMarkdownDetails(org string, provider string, resourcePrefix string, kind

repoPath, err := getRepoPath(githost, org, provider, providerModuleVersion)
if err != nil {
msg := "Skip getMarkdownDetails(rawname=%q) because getRepoPath(%q, %q, %q, %q) failed: %v"
sink.Debugf(&diag.Diag{Message: msg}, rawname, githost, org, provider, providerModuleVersion, err)
return nil, "", false
}

Expand Down Expand Up @@ -251,8 +256,8 @@ func getDocsForProvider(g *Generator, org string, provider string, resourcePrefi
return entityDocs{}, nil
}

markdownBytes, markdownFileName, found := getMarkdownDetails(org, provider, resourcePrefix, kind, rawname, info,
providerModuleVersion, githost)
markdownBytes, markdownFileName, found := getMarkdownDetails(g.sink, org, provider,
resourcePrefix, kind, rawname, info, providerModuleVersion, githost)
if !found {
entitiesMissingDocs++
msg := fmt.Sprintf("could not find docs for %v %v. Override the Docs property in the %v mapping. See "+
Expand Down