Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve resolution error output to include current status #131

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions internal/resolution/job/base_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ package job

import (
"errors"
"fmt"
"os/exec"
)

type BaseJob struct {
file string
errs IErrors
status chan string
file string
errs IErrors
status chan string
currentStatus string
}

func NewBaseJob(file string) BaseJob {
return BaseJob{
file: file,
errs: NewErrors(file),
status: make(chan string),
file: file,
errs: NewErrors(file),
status: make(chan string),
currentStatus: "",
}
}

Expand All @@ -31,7 +34,23 @@ func (j *BaseJob) ReceiveStatus() chan string {
return j.status
}

func (j *BaseJob) FmtError(err error, output []byte) error {

if err == nil {
return fmt.Errorf("%s error: No error was present.", j.currentStatus)
}

errorString := fmt.Errorf("%s error: %s", j.currentStatus, err)

if output != nil {
errorString = fmt.Errorf("%s output: %s\n%s", j.currentStatus, output, errorString)
}

return errorString
}

func (j *BaseJob) SendStatus(status string) {
j.currentStatus = status
j.status <- status
}

Expand Down
24 changes: 24 additions & 0 deletions internal/resolution/job/base_job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package job

import (
"errors"
"fmt"
"os/exec"
"testing"

Expand Down Expand Up @@ -34,6 +35,29 @@ func TestReceiveStatus(t *testing.T) {
assert.NotNil(t, statusChan)
}

func TestFmtError(t *testing.T) {
j := BaseJob{
file: testFile,
errs: nil,
status: make(chan string),
}
statusMsg := "statusMsg"
go func() {
status := <-j.ReceiveStatus()
assert.Equal(t, "statusMsg", status)
}()

j.SendStatus(statusMsg)

errorMsg := fmt.Errorf("statusMsg error: test-error")
formattedError := j.FmtError(fmt.Errorf("test-error"), nil)
assert.Equal(t, errorMsg, formattedError)

errorMsg = fmt.Errorf("statusMsg output: test\nstatusMsg error: test-error")
formattedError = j.FmtError(fmt.Errorf("test-error"), []byte("test"))
assert.Equal(t, errorMsg, formattedError)
}

func TestErrors(t *testing.T) {
jobErr := errors.New("error")
j := BaseJob{}
Expand Down
12 changes: 6 additions & 6 deletions internal/resolution/pm/pip/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,30 +67,30 @@ func (j *Job) Run() {
j.SendStatus("removing venv")
err := j.pipCleaner.RemoveAll(j.venvPath)
if err != nil {
j.Errors().Critical(err)
j.Errors().Critical(j.FmtError(err, nil))
}
}()

j.SendStatus("creating venv")
_, err := j.runCreateVenvCmd()
output, err := j.runCreateVenvCmd()
if err != nil {
j.Errors().Critical(err)
j.Errors().Critical(j.FmtError(err, output))

return
}

j.SendStatus("installing requirements")
_, err = j.runInstallCmd()
if err != nil {
j.Errors().Critical(err)
j.Errors().Critical(j.FmtError(err, nil))

return
}
}

err := j.writeLockContent()
if err != nil {
j.Errors().Critical(err)
j.Errors().Critical(j.FmtError(err, nil))

return
}
Expand Down Expand Up @@ -147,7 +147,7 @@ func (j *Job) runCreateVenvCmd() ([]byte, error) {

createVenvCmdOutput, err := createVenvCmd.Output()
if err != nil {
return nil, j.GetExitError(err)
return createVenvCmdOutput, j.GetExitError(err)
}

return createVenvCmdOutput, nil
Expand Down
Loading