Skip to content

Commit 207ed54

Browse files
committed
Improve vscode error description
1 parent 83f7d9e commit 207ed54

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

internal/vscode/cli.go

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package vscode
22

33
import (
4+
"bytes"
45
"fmt"
56
"os"
67
"os/exec"
78
"path/filepath"
9+
"regexp"
810
"runtime"
11+
"strings"
912

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

30-
cmdOutput, err := exec.Command(CLIPath, arg...).CombinedOutput()
33+
cmd := exec.Command(CLIPath, arg...)
3134

32-
return string(cmdOutput), err
35+
var stdout bytes.Buffer
36+
var stderr bytes.Buffer
37+
38+
cmd.Stdout = &stdout
39+
cmd.Stderr = &stderr
40+
41+
err = cmd.Run()
42+
43+
if err != nil {
44+
newLineRegExp := regexp.MustCompile(`\n+`)
45+
46+
return "", fmt.Errorf(
47+
"Error while calling the Visual Studio Code CLI:\n\n%s\n\n%s",
48+
strings.TrimSpace(
49+
newLineRegExp.ReplaceAllLiteralString(stderr.String(), " "),
50+
),
51+
err.Error(),
52+
)
53+
}
54+
55+
return stdout.String(), nil
3356
}
3457

3558
func (c CLI) LookupPath(operatingSystem string) (string, error) {

internal/vscode/extensions.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,10 @@ func NewExtensions() Extensions {
88

99
func (e Extensions) Install(extensionName string) (string, error) {
1010
c := CLI{}
11-
return c.Exec("--install-extension", extensionName, "--force")
11+
12+
return c.Exec(
13+
"--install-extension",
14+
extensionName,
15+
"--force",
16+
)
1217
}

internal/vscode/process.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ func NewProcess() Process {
88

99
func (p Process) OpenOnRemote(hostKey, pathToOpen string) (string, error) {
1010
c := CLI{}
11+
1112
return c.Exec(
1213
"--new-window",
1314
"--skip-release-notes",

0 commit comments

Comments
 (0)