From 8a0614e8f9cf32f596375e2737e48a87842ddd6a Mon Sep 17 00:00:00 2001 From: Zachary Stewart Date: Sun, 2 Sep 2018 22:53:35 -0400 Subject: [PATCH] Return a well-defined type when an invalid graph is detected --- error.go | 13 +++++++++++++ workflow.go | 3 +-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 error.go diff --git a/error.go b/error.go new file mode 100644 index 0000000..b3a0d35 --- /dev/null +++ b/error.go @@ -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 +} diff --git a/workflow.go b/workflow.go index 1bf8a80..c139d81 100644 --- a/workflow.go +++ b/workflow.go @@ -2,7 +2,6 @@ package workflow import ( "context" - "errors" ) var empty struct{} @@ -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