Skip to content

Commit

Permalink
Add better error from nvm
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomationD committed Aug 7, 2024
1 parent 1b20ee8 commit 9007659
Showing 1 changed file with 75 additions and 15 deletions.
90 changes: 75 additions & 15 deletions internal/manager/serverless/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,23 @@ func (sls *Manager) runNvm(w io.Writer) error {

cmd := exec.Command("bash", "-c", command)

return term.New(
// Capture stderr in a buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr

t := term.New(
term.WithDir(sls.App.Path),
term.WithStdout(w),
term.WithStderr(w),
).InteractiveRun(cmd)
term.WithStderr(&stderr),
)

err = t.InteractiveRun(cmd)
if err != nil {
// Return the error along with stderr output
return fmt.Errorf("command failed with error: %w, stderr: %s", err, stderr.String())
}

return nil
}

func (sls *Manager) runDeploy(w io.Writer) error {
Expand Down Expand Up @@ -165,11 +177,23 @@ func (sls *Manager) runDeploy(w io.Writer) error {

cmd := exec.Command("bash", "-c", command)

return term.New(
// Capture stderr in a buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr

t := term.New(
term.WithDir(sls.App.Path),
term.WithStdout(w),
term.WithStderr(w),
).InteractiveRun(cmd)
term.WithStderr(&stderr),
)

err := t.InteractiveRun(cmd)
if err != nil {
// Return the error along with stderr output
return fmt.Errorf("command failed with error: %w, stderr: %s", err, stderr.String())
}

return nil
}

func (sls *Manager) runRemove(w io.Writer) error {
Expand Down Expand Up @@ -221,11 +245,23 @@ func (sls *Manager) runRemove(w io.Writer) error {

cmd := exec.Command("bash", "-c", command)

return term.New(
// Capture stderr in a buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr

t := term.New(
term.WithDir(sls.App.Path),
term.WithStdout(w),
term.WithStderr(w),
).InteractiveRun(cmd)
term.WithStderr(&stderr),
)

err := t.InteractiveRun(cmd)
if err != nil {
// Return the error along with stderr output
return fmt.Errorf("command failed with error: %w, stderr: %s", err, stderr.String())
}

return nil
}

func (sls *Manager) runCreateDomain(w io.Writer) error {
Expand Down Expand Up @@ -254,11 +290,23 @@ func (sls *Manager) runCreateDomain(w io.Writer) error {

cmd := exec.Command("bash", "-c", command)

return term.New(
// Capture stderr in a buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr

t := term.New(
term.WithDir(sls.App.Path),
term.WithStdout(w),
term.WithStderr(w),
).InteractiveRun(cmd)
term.WithStderr(&stderr),
)

err := t.InteractiveRun(cmd)
if err != nil {
// Return the error along with stderr output
return fmt.Errorf("command failed with error: %w, stderr: %s", err, stderr.String())
}

return nil
}

func (sls *Manager) runRemoveDomain(w io.Writer) error {
Expand Down Expand Up @@ -287,11 +335,23 @@ func (sls *Manager) runRemoveDomain(w io.Writer) error {

cmd := exec.Command("bash", "-c", command)

return term.New(
// Capture stderr in a buffer
var stderr bytes.Buffer
cmd.Stderr = &stderr

t := term.New(
term.WithDir(sls.App.Path),
term.WithStdout(w),
term.WithStderr(w),
).InteractiveRun(cmd)
term.WithStderr(&stderr),
)

err := t.InteractiveRun(cmd)
if err != nil {
// Return the error along with stderr output
return fmt.Errorf("command failed with error: %w, stderr: %s", err, stderr.String())
}

return nil
}

func npmToYarn(cmd string) string {
Expand Down

0 comments on commit 9007659

Please sign in to comment.