From 2b60e5db76d633fdb0326922f6c12f0f065c3fc8 Mon Sep 17 00:00:00 2001 From: kmoe <5575356+kmoe@users.noreply.github.com> Date: Thu, 15 Apr 2021 18:20:04 +0100 Subject: [PATCH] improve error logging in example code --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 00a72870..69a0bb93 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ import ( "fmt" "io/ioutil" "os" + "log" "github.com/hashicorp/terraform-exec/tfexec" "github.com/hashicorp/terraform-exec/tfinstall" @@ -36,29 +37,29 @@ import ( func main() { tmpDir, err := ioutil.TempDir("", "tfinstall") if err != nil { - panic(err) + log.Fatalf("error creating temp dir: %s", err) } defer os.RemoveAll(tmpDir) execPath, err := tfinstall.Find(context.Background(), tfinstall.LatestVersion(tmpDir, false)) if err != nil { - panic(err) + log.Fatalf("error locating Terraform binary: %s", err) } workingDir := "/path/to/working/dir" tf, err := tfexec.NewTerraform(workingDir, execPath) if err != nil { - panic(err) + log.Fatalf("error running NewTerraform: %s", err) } err = tf.Init(context.Background(), tfexec.Upgrade(true)) if err != nil { - panic(err) + log.Fatalf("error running Init: %s", err) } state, err := tf.Show(context.Background()) if err != nil { - panic(err) + log.Fatalf("error running Show: %s", err) } fmt.Println(state.FormatVersion) // "0.1"