Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelvigee committed May 12, 2024
1 parent 8368b6f commit 16d439f
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 50 deletions.
11 changes: 10 additions & 1 deletion bootstrap/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ import (
"go.uber.org/multierr"
"io"
"os"
"strconv"
"sync"
)

var skipPathLogFile bool

func init() {
skipPathLogFile, _ = strconv.ParseBool(os.Getenv("HEPH_SKIP_PATH_LOG"))
}

func PrintHumanError(err error) {
errs := worker2.CollectRootErrors(err)
skippedCount := 0
Expand Down Expand Up @@ -55,7 +62,9 @@ func PrintHumanError(err error) {
f.Close()
fmt.Fprintln(log.Writer())
}
log.Errorf("The log file can be found at %v", logFile)
if !skipPathLogFile {
log.Errorf("The log file can be found at %v", logFile)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def e2e_test(
cmd = "(" + cmd + ")"

if expected_failure:
test_cmd = '%s | tee output && RC=$? || RC=$?; if [ $RC -eq 0 ]; then exit 1; fi; echo "Command exited with code $RC, as expected"; ' % cmd
test_cmd = '%s 2>&1 | tee output && RC=$? || RC=$?; if [ $RC -eq 0 ]; then exit 1; fi; echo "Command exited with code $RC, as expected"; ' % cmd
else:
test_cmd = "%s | tee output && RC=$? " % cmd

Expand Down
34 changes: 34 additions & 0 deletions test/features/errors.BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("//test", "e2e_test")

will_err = target(
name = "_will_err",
run = "echo failed; exit 1",
cache = False,
)

target(
name = "err1",
deps = will_err,
cache = False,
labels = 'will-err',
)

target(
name = "err2",
deps = will_err,
cache = False,
labels = 'will-err',
)

e2e_test(
name = "e2e_errors",
cmd = "HEPH_SKIP_PATH_LOG=1 heph run '//test/features && will-err'",
expected_failure = True,
expected_output = """
ERR| //test/features:_will_err failed: exec: exit status 1

failed

ERR| exec: exit status 1
""".strip(),
)
20 changes: 9 additions & 11 deletions worker2/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,23 +157,21 @@ func (e *Engine) tryFreeze(depObj *Node[Dep]) (bool, error) {
}

switch state {
case ExecStateSkipped:
errs.Add(depExec.Err)
case ExecStateFailed:
case ExecStateSkipped, ExecStateFailed:
for _, err := range multierr.Errors(depExec.Err) {
if serr, ok := xerrors.As[xcontext.SignalCause](err); ok {
errs.Add(serr)
} else {
if jerr, ok := xerrors.As[Error](err); ok {
err = jerr.Root()
errs.Add(jerr.Root())
} else {
errs.Add(Error{
ID: depExec.ID,
State: depExec.State,
Name: depExec.Dep.GetName(),
Err: err,
})
}

errs.Add(Error{
ID: depExec.ID,
State: depExec.State,
Name: depExec.Dep.GetName(),
Err: err,
})
}
}
}
Expand Down
46 changes: 18 additions & 28 deletions worker2/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,19 @@ func TestExecErrorSkip(t *testing.T) {
err2 := <-err2Ch
err3 := <-err3Ch

assert.Equal(t, err1, errors.New("beep bop"))
assert.Equal(t, err2, Error{
assert.Equal(t, errors.New("beep bop"), err1)
assert.Equal(t, Error{
ID: 1,
Name: "a1",
State: ExecStateFailed,
Err: errors.New("beep bop"),
})
assert.Equal(t, err3, Error{
ID: 2,
Name: "a2",
State: ExecStateSkipped,
Err: Error{
ID: 1,
Name: "a1",
State: ExecStateFailed,
Err: errors.New("beep bop"),
},
})
}, err2)
assert.Equal(t, Error{
ID: 1,
Name: "a1",
State: ExecStateFailed,
Err: errors.New("beep bop"),
}, err3)
}

func TestExecErrorSkipStress(t *testing.T) {
Expand Down Expand Up @@ -331,28 +326,23 @@ func TestExecErrorSkipStress(t *testing.T) {
for _, errCh := range errChs2 {
err := <-errCh

assert.Equal(t, err, Error{
assert.Equal(t, Error{
ID: 1,
Name: "a1",
State: ExecStateFailed,
Err: errors.New("beep bop"),
})
}, err)
}

for _, c := range errChs3 {
err := <-c.ch

assert.Equal(t, err, Error{
ID: c.d.getExecution().ID,
Name: c.d.GetName(),
State: ExecStateSkipped,
Err: Error{
ID: 1,
Name: "a1",
State: ExecStateFailed,
Err: errors.New("beep bop"),
},
})
require.Equal(t, Error{
ID: 1,
Name: "a1",
State: ExecStateFailed,
Err: errors.New("beep bop"),
}, err)
}
}

Expand Down Expand Up @@ -385,7 +375,7 @@ func TestExecCancel(t *testing.T) {

err := <-errCh

assert.ErrorIs(t, err, context.Canceled)
assert.ErrorIs(t, context.Canceled, err)
}

func TestExecDeps(t *testing.T) {
Expand Down
11 changes: 3 additions & 8 deletions worker2/error.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package worker2

import (
"context"
"errors"
"fmt"
"go.uber.org/multierr"
Expand All @@ -27,11 +26,7 @@ func CollectUniqueErrors(inErrs []error) []error {
for _, err := range inErrs {
var jerr Error
if errors.As(err, &jerr) {
if errors.Is(err, context.Canceled) {
merrs[err] = struct{}{}
} else {
jerrs[jerr.ID] = jerr
}
jerrs[jerr.ID] = jerr
} else {
merrs[err] = struct{}{}
}
Expand All @@ -54,7 +49,7 @@ func CollectRootErrors(err error) []error {
for _, err := range multierr.Errors(err) {
var jerr Error
if errors.As(err, &jerr) {
errs = append(errs, jerr.Err)
errs = append(errs, jerr.Root())
} else {
errs = append(errs, err)
}
Expand All @@ -69,7 +64,7 @@ func (e *Error) Root() error {
}

if !e.Skipped() {
return e
return *e
}

var roots []error
Expand Down
5 changes: 4 additions & 1 deletion worker2/poolwait/wait.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/hephbuild/heph/log/log"
"github.com/hephbuild/heph/utils/xtea"
"github.com/hephbuild/heph/worker2"
"go.uber.org/multierr"
"os"
"strconv"
"time"
Expand Down Expand Up @@ -47,5 +48,7 @@ func Wait(ctx context.Context, name string, pool *worker2.Engine, deps worker2.D
}
}

return deps.GetErr()
err := deps.GetErr()

return multierr.Combine(worker2.CollectRootErrors(err)...)
}

0 comments on commit 16d439f

Please sign in to comment.