Skip to content

Commit

Permalink
Replace most of terraform/exec w/ terraform-exec (#271)
Browse files Browse the repository at this point in the history
* Replace most of terraform/exec w/ terraform-exec

* go mod tidy
  • Loading branch information
radeksimko authored Oct 8, 2020
1 parent 673548b commit 7666e9d
Show file tree
Hide file tree
Showing 28 changed files with 1,008 additions and 680 deletions.
2 changes: 1 addition & 1 deletion docs/TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Log paths support template syntax. This allows sane separation of logs while acc
- `timestamp` - current timestamp (formatted as [`Time.Unix()`](https://golang.org/pkg/time/#Time.Unix), i.e. the number of seconds elapsed since January 1, 1970 UTC)
- `lsPid` - process ID of the language server
- `lsPpid` - parent process ID of the language server (typically editor's or editor plugin's PID)
- `args` - all arguments passed to `terraform` turned into a safe `-` separated string
- `method` - [`terraform-exec`](https://pkg.go.dev/github.com/hashicorp/terraform-exec) method (e.g. `Format` or `Version`)

The path is interpreted as [Go template](https://golang.org/pkg/text/template/), e.g. `/tmp/terraform-ls-{{timestamp}}.log`.

Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@ require (
github.com/gammazero/workerpool v1.0.0
github.com/google/go-cmp v0.5.1
github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-version v1.2.0
github.com/hashicorp/go-version v1.2.1
github.com/hashicorp/hcl/v2 v2.5.2-0.20200528183353-fa7c453538de
github.com/hashicorp/terraform-config-inspect v0.0.0-20200806211835-c481b8bfa41e
github.com/hashicorp/terraform-exec v0.11.1-0.20201007122305-ea2094d52cb5
github.com/hashicorp/terraform-json v0.5.0
github.com/hashicorp/terraform-svchost v0.0.0-20191119180714-d2e4933b9136
github.com/mh-cbon/go-fmt-fail v0.0.0-20160815164508-67765b3fbcb5
github.com/mitchellh/cli v1.0.0
github.com/mitchellh/cli v1.1.1
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.2
github.com/pmezard/go-difflib v1.0.0
github.com/sourcegraph/go-lsp v0.0.0-20200117082640-b19bb38222e2
github.com/spf13/afero v1.3.2
github.com/stretchr/testify v1.4.0
github.com/vektra/mockery/v2 v2.3.0
github.com/zclconf/go-cty v1.2.1
golang.org/x/net v0.0.0-20191009170851-d66e71096ffb
golang.org/x/net v0.0.0-20200301022130-244492dfa37a
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
)

replace github.com/sourcegraph/go-lsp => github.com/radeksimko/go-lsp v0.1.0
381 changes: 381 additions & 0 deletions go.sum

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions internal/terraform/exec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,19 @@ type ExitError struct {
Err *exec.ExitError
CtxErr error

Path string
Stdout string
Stderr string
Method string
}

func (e *ExitError) Unwrap() error {
return e.CtxErr
}

func (e *ExitError) Error() string {
out := fmt.Sprintf("terraform (pid %d) exited (code %d): %s\nstdout: %q\nstderr: %q",
out := fmt.Sprintf("terraform %q (pid %d) exited (code %d): %s",
e.Method,
e.Err.Pid(),
e.Err.ExitCode(),
e.Err.ProcessState.String(),
e.Stdout,
e.Stderr)

e.Err.ProcessState.String())
if e.CtxErr != nil {
return fmt.Sprintf("%s.\n%s", e.CtxErr, e.Err)
}
Expand All @@ -36,7 +32,7 @@ func (e *ExitError) Error() string {
}

type execTimeoutErr struct {
args []string
method string
duration time.Duration
}

Expand All @@ -46,25 +42,25 @@ func (e *execTimeoutErr) Is(target error) bool {

func (e *execTimeoutErr) Error() string {
return fmt.Sprintf("Execution of %q timed out after %s",
e.args, e.duration)
e.method, e.duration)
}

func ExecTimeoutError(args []string, duration time.Duration) *execTimeoutErr {
return &execTimeoutErr{args, duration}
func ExecTimeoutError(method string, duration time.Duration) *execTimeoutErr {
return &execTimeoutErr{method, duration}
}

type execCanceledErr struct {
cmd []string
method string
}

func (e *execCanceledErr) Is(target error) bool {
return reflect.DeepEqual(e, target)
}

func (e *execCanceledErr) Error() string {
return fmt.Sprintf("Execution of %q canceled", e.cmd)
return fmt.Sprintf("Execution of %q canceled", e.method)
}

func ExecCanceledError(cmd []string) *execCanceledErr {
return &execCanceledErr{cmd}
func ExecCanceledError(method string) *execCanceledErr {
return &execCanceledErr{method}
}
Loading

0 comments on commit 7666e9d

Please sign in to comment.