Skip to content

Commit

Permalink
Improve vscode error description
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremylevy committed Jun 1, 2022
1 parent 83f7d9e commit 207ed54
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
27 changes: 25 additions & 2 deletions internal/vscode/cli.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package vscode

import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"

"github.com/recode-sh/cli/internal/system"
)
Expand All @@ -27,9 +30,29 @@ func (c CLI) Exec(arg ...string) (string, error) {
return "", err
}

cmdOutput, err := exec.Command(CLIPath, arg...).CombinedOutput()
cmd := exec.Command(CLIPath, arg...)

return string(cmdOutput), err
var stdout bytes.Buffer
var stderr bytes.Buffer

cmd.Stdout = &stdout
cmd.Stderr = &stderr

err = cmd.Run()

if err != nil {
newLineRegExp := regexp.MustCompile(`\n+`)

return "", fmt.Errorf(
"Error while calling the Visual Studio Code CLI:\n\n%s\n\n%s",
strings.TrimSpace(
newLineRegExp.ReplaceAllLiteralString(stderr.String(), " "),
),
err.Error(),
)
}

return stdout.String(), nil
}

func (c CLI) LookupPath(operatingSystem string) (string, error) {
Expand Down
7 changes: 6 additions & 1 deletion internal/vscode/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,10 @@ func NewExtensions() Extensions {

func (e Extensions) Install(extensionName string) (string, error) {
c := CLI{}
return c.Exec("--install-extension", extensionName, "--force")

return c.Exec(
"--install-extension",
extensionName,
"--force",
)
}
1 change: 1 addition & 0 deletions internal/vscode/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ func NewProcess() Process {

func (p Process) OpenOnRemote(hostKey, pathToOpen string) (string, error) {
c := CLI{}

return c.Exec(
"--new-window",
"--skip-release-notes",
Expand Down

0 comments on commit 207ed54

Please # to comment.