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 1f5fd2d commit 1b20ee8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions internal/manager/serverless/native.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package serverless

import (
"bytes"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -49,15 +50,28 @@ func (sls *Manager) nvm(w io.Writer, command string) error {
return err
}

logrus.Debugf("Running: bash -c source %s/nvm.sh && nvm install %s && %s", nvmDir, sls.App.NodeVersion, command)
cmd := exec.Command("bash", "-c",
fmt.Sprintf("source %s/nvm.sh && nvm install %s && %s", nvmDir, sls.App.NodeVersion, 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) readNvmrc() error {
Expand All @@ -70,6 +84,7 @@ func (sls *Manager) readNvmrc() error {
}
sls.App.NodeVersion = strings.TrimSpace(string(file))
}

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/manager/serverless/serverless.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (sls *Manager) Nvm(ui terminal.UI, command []string) error {

err := sls.nvm(s.TermOutput(), strings.Join(command, " "))
if err != nil {
return fmt.Errorf("can't run nvm: %w", err)
return fmt.Errorf("can't run nvm: %s ", err)
}

s.Done()
Expand Down

0 comments on commit 1b20ee8

Please sign in to comment.