-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b8a87b
commit e582e84
Showing
5 changed files
with
187 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dependencies | ||
|
||
// Action is a struct representing an action request for the tree by a watcher function. | ||
// All modification operations on the tree should be done using an Action and not directly | ||
// inside a watchers scope, to avoid bugs with operations order. | ||
type Action interface{} | ||
|
||
// CancelNodeAddAction cancel the node add to the manager, and cause all its dependencies to be | ||
// removed as well if they are not needed by any other node (similar to UnselectEvent). | ||
// This action will not prevent other watchers from being called. | ||
// When cancelled, event remove watchers will be called to allow cleaning. | ||
// Please use this action instead of calling UnselectEvent directly to avoid bugs with | ||
// operations order. | ||
type CancelNodeAddAction struct { | ||
Reason error | ||
} | ||
|
||
func NewCancelNodeAddAction(reason error) *CancelNodeAddAction { | ||
return &CancelNodeAddAction{Reason: reason} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package dependencies | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
// ErrNodeAddCancelled is the error produced when cancelling a node add to the manager | ||
// using the CancelNodeAddAction Action. | ||
type ErrNodeAddCancelled struct { | ||
Reasons []error | ||
} | ||
|
||
func NewErrNodeAddCancelled(reasons []error) *ErrNodeAddCancelled { | ||
return &ErrNodeAddCancelled{Reasons: reasons} | ||
} | ||
|
||
func (cancelErr *ErrNodeAddCancelled) Error() string { | ||
var errorsStrings []string | ||
for _, err := range cancelErr.Reasons { | ||
errorsStrings = append(errorsStrings, err.Error()) | ||
} | ||
return fmt.Sprintf("node add was cancelled, reasons: \"%s\"", strings.Join(errorsStrings, "\", \"")) | ||
} | ||
|
||
func (cancelErr *ErrNodeAddCancelled) AddReason(reason error) { | ||
cancelErr.Reasons = append(cancelErr.Reasons, reason) | ||
} | ||
|
||
var ( | ||
ErrNodeType = errors.New("unsupported node type") | ||
ErrNodeNotFound = errors.New("node not found") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.