Skip to content
Merged
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
3 changes: 3 additions & 0 deletions build_step.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ func (sb *StepBuilder) BuildStep(s Steper) {
return TraverseEndBranch // it's a sub-workflow, let it manage its own steps
}
if b, ok := s.(interface{ BuildStep() }); ok {
if r, ok := s.(interface{ Reset() }); ok {
r.Reset() // reset the step before building
}
b.BuildStep()
sb.built.Add(s)
return TraverseEndBranch // not necessary to go deeper
Expand Down
16 changes: 8 additions & 8 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ type StepResult struct {
func (e StepResult) Error() string {
rv := fmt.Sprintf("[%s]", e.Status)
if e.Err != nil {
rv += "\n\t" + strings.ReplaceAll(e.Err.Error(), "\n", "\n\t")
rv += "\n\t" + indent(e.Err.Error())
}
return rv
}
func (e StepResult) Unwrap() error { return e.Err }

func indent(s string) string { return strings.ReplaceAll(s, "\n", "\n\t") }

// ErrWorkflow contains all errors reported from terminated Steps in Workflow.
//
// Keys are root Steps, values are its status and error.
Expand Down Expand Up @@ -172,18 +174,16 @@ var ErrWorkflowIsRunning = fmt.Errorf("Workflow is running, please wait for it t
type ErrCycleDependency map[Steper][]Steper

func (e ErrCycleDependency) Error() string {
var builder strings.Builder
builder.WriteString("Cycle Dependency Error:")
depErr := make([]string, 0, len(e))
for step, ups := range e {
depsStr := []string{}
for _, up := range ups {
depsStr = append(depsStr, String(up))
}
builder.WriteRune('\n')
builder.WriteString(fmt.Sprintf(
"%s: [%s]",
String(step), strings.Join(depsStr, ", "),
depErr = append(depErr, fmt.Sprintf(
"%s depends on [\n\t%s\n]",
String(step), indent(strings.Join(depsStr, "\n")),
))
}
return builder.String()
return fmt.Sprintf("Cycle Dependency Error:\n\t%s", indent(strings.Join(depErr, "\n")))
}
2 changes: 1 addition & 1 deletion error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ func TestErrCycleDependency(t *testing.T) {
)
var errCycle flow.ErrCycleDependency
if assert.ErrorAs(t, w.Do(context.Background()), &errCycle) {
assert.ErrorContains(t, errCycle, "Succeeded: [Succeeded]")
assert.ErrorContains(t, errCycle, "Succeeded depends on [\n\t\tSucceeded\n\t]")
}
}
6 changes: 3 additions & 3 deletions wrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ func String(step Steper) string {
case interface{ String() string }:
return u.String()
case interface{ Unwrap() Steper }:
return String(u.Unwrap())
return fmt.Sprintf("%T(%p) {\n\t%s\n}", u, u, indent(String(u.Unwrap())))
case interface{ Unwrap() []Steper }:
stepStrs := []string{}
for _, step := range u.Unwrap() {
stepStrs = append(stepStrs, String(step))
}
return fmt.Sprintf("[%s]", strings.Join(stepStrs, ", "))
return fmt.Sprintf("%T(%p) {\n\t%s\n}", u, u, indent(strings.Join(stepStrs, "\n")))
default:
return fmt.Sprintf("%T(%v)", step, step)
return fmt.Sprintf("%T(%p)", step, step)
}
}

Expand Down
5 changes: 4 additions & 1 deletion wrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,12 @@ func TestString(t *testing.T) {
var (
a = NoOp("a")
b = NoOp("b")
A = wrap(a)
ab = multi(a, b)
)
assert.Equal(t, "<nil>", String(nil))
assert.Equal(t, "a", String(a))
assert.Equal(t, "[a, b]", String(ab))
assert.Equal(t, "A", String(A))
assert.Contains(t, String(ab), "*flow.multiStep")
assert.Contains(t, String(ab), " {\n\ta\n\tb\n}")
}