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

product: Consider using logger and capture stdout/stderr in GetVersion #46

Open
radeksimko opened this issue Dec 6, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@radeksimko
Copy link
Member

Currently getting product version may fail in some rare cases and while we would report this as an error, we don't explicitly capture the stdout or stderr to make debugging of such problems easier.

GetVersion: func(ctx context.Context, path string) (*version.Version, error) {
cmd := exec.CommandContext(ctx, path, "version")
out, err := cmd.Output()
if err != nil {
return nil, err
}
stdout := strings.TrimSpace(string(out))
submatches := terraformVersionOutputRe.FindStringSubmatch(stdout)
if len(submatches) != 2 {
return nil, fmt.Errorf("unexpected number of version matches %d for %s", len(submatches), stdout)
}
v, err := version.NewVersion(submatches[1])
if err != nil {
return nil, fmt.Errorf("unable to parse version %q: %w", submatches[1], err)
}
return v, err
},

See also hashicorp/terraform-plugin-sdk#823

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant