(ctx context.Context, binaryPath string)
| 181 | } |
| 182 | |
| 183 | func versionFromBinaryPath(ctx context.Context, binaryPath string) (*version.Version, error) { |
| 184 | if ctx.Err() != nil { |
| 185 | return nil, ctx.Err() |
| 186 | } |
| 187 | |
| 188 | // #nosec |
| 189 | cmd := exec.CommandContext(ctx, binaryPath, "version", "-json") |
| 190 | out, err := cmd.Output() |
| 191 | if err != nil { |
| 192 | select { |
| 193 | // `exec` library throws a `signal: killed`` error instead of the canceled context. |
| 194 | // Since we know the cause for the killed signal, we are throwing the relevant error here. |
| 195 | case <-ctx.Done(): |
| 196 | return nil, ctx.Err() |
| 197 | default: |
| 198 | return nil, err |
| 199 | } |
| 200 | } |
| 201 | vj := tfjson.VersionOutput{} |
| 202 | err = json.Unmarshal(out, &vj) |
| 203 | if err != nil { |
| 204 | return nil, err |
| 205 | } |
| 206 | return version.NewVersion(vj.Version) |
| 207 | } |
| 208 | |
| 209 | type textFileBusyError struct { |
| 210 | exitErr *exec.ExitError |
no test coverage detected