Skip to content

Commit

Permalink
Return a well-defined type when an invalid graph is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
ztstewart committed Sep 3, 2018
1 parent 70dfc26 commit 8a0614e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 13 additions & 0 deletions error.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package workflow

const (
_invalidGraphMsg = "dependency graph is unsolvable; check for cycles or missing dependencies"
)

// An InvalidGraphError is use to mark a dependency graph as being invalid.
// It is returned when a graph has unmet dependencies or cycles.
type InvalidGraphError struct{}

func (ige InvalidGraphError) Error() string {
return _invalidGraphMsg
}
3 changes: 1 addition & 2 deletions workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package workflow

import (
"context"
"errors"
)

var empty struct{}
Expand Down Expand Up @@ -120,7 +119,7 @@ func (g Graph) isWellFormed() error {
// once somehow, we either are missing a dependency or we have a cycle.
// Either way, we can't execute the graph.
if visitedJobs != len(g.tasks) {
return errors.New("dependency graph is unsolvable; check for cycles or missing dependencies")
return InvalidGraphError{}
}

return nil
Expand Down

0 comments on commit 8a0614e

Please sign in to comment.