Skip to content

Commit 774e830

Browse files
committed
For validation errors that relate to limits, include the count in the message
1 parent 3665840 commit 774e830

File tree

5 files changed

+19
-22
lines changed

5 files changed

+19
-22
lines changed

flows/definition/flow.go

+2-8
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ import (
2121
"github.com/nyaruka/goflow/utils"
2222
)
2323

24-
const (
25-
maxNodesPerFlow = 1000 // max number of nodes in a flow
26-
maxActionsPerNode = 100 // max number of actions in a node
27-
maxExitsPerNode = 100 // max number of exits in a node
28-
)
29-
3024
// CurrentSpecVersion is the flow spec version supported by this library
3125
var CurrentSpecVersion = semver.MustParse("14.0.0")
3226
var CurrentSupportedSpecs, _ = semver.NewConstraint(">= 11.0.0, < 14.1.0")
@@ -110,8 +104,8 @@ func (f *flow) ExpireAfter() time.Duration {
110104
}
111105

112106
func (f *flow) validate() error {
113-
if len(f.nodes) > maxNodesPerFlow {
114-
return fmt.Errorf("flow can't have more than %d nodes", maxNodesPerFlow)
107+
if len(f.nodes) > flows.MaxNodesPerFlow {
108+
return fmt.Errorf("flow can't have more than %d nodes (has %d)", flows.MaxNodesPerFlow, len(f.nodes))
115109
}
116110

117111
// track UUIDs used by nodes and actions to ensure that they are unique

flows/definition/flow_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,19 @@ func TestBrokenFlows(t *testing.T) {
104104
},
105105
{
106106
"too_many_nodes.json",
107-
"flow can't have more than 1000 nodes",
107+
"flow can't have more than 1000 nodes (has 1001)",
108108
},
109109
{
110110
"too_many_actions.json",
111-
"invalid node[uuid=a58be63b-907d-4a1a-856b-0bb5579d7507]: node can't have more than 100 actions",
111+
"invalid node[uuid=a58be63b-907d-4a1a-856b-0bb5579d7507]: node can't have more than 100 actions (has 101)",
112112
},
113113
{
114114
"too_many_exits.json",
115-
"invalid node[uuid=a58be63b-907d-4a1a-856b-0bb5579d7507]: node can't have more than 100 exits",
115+
"invalid node[uuid=a58be63b-907d-4a1a-856b-0bb5579d7507]: node can't have more than 100 exits (has 101)",
116116
},
117117
{
118118
"too_many_categories.json",
119-
"invalid node[uuid=a58be63b-907d-4a1a-856b-0bb5579d7507]: invalid router: router can't have more than 100 categories",
119+
"invalid node[uuid=a58be63b-907d-4a1a-856b-0bb5579d7507]: invalid router: router can't have more than 100 categories (has 101)",
120120
},
121121
}
122122

flows/definition/node.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ func (n *node) Router() flows.Router { return n.router }
3838
func (n *node) Exits() []flows.Exit { return n.exits }
3939

4040
func (n *node) Validate(flow flows.Flow, seenUUIDs map[uuids.UUID]bool) error {
41-
if len(n.actions) > maxActionsPerNode {
42-
return fmt.Errorf("node can't have more than %d actions", maxActionsPerNode)
41+
if len(n.actions) > flows.MaxActionsPerNode {
42+
return fmt.Errorf("node can't have more than %d actions (has %d)", flows.MaxActionsPerNode, len(n.actions))
4343
}
44-
if len(n.exits) > maxExitsPerNode {
45-
return fmt.Errorf("node can't have more than %d exits", maxExitsPerNode)
44+
if len(n.exits) > flows.MaxExitsPerNode {
45+
return fmt.Errorf("node can't have more than %d exits (has %d)", flows.MaxExitsPerNode, len(n.exits))
4646
}
4747

4848
// validate all the node's actions

flows/interfaces.go

+7
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ import (
1616
"github.com/nyaruka/goflow/utils"
1717
)
1818

19+
const (
20+
MaxNodesPerFlow = 1000 // max number of nodes in a flow
21+
MaxActionsPerNode = 100 // max number of actions in a node
22+
MaxExitsPerNode = 100 // max number of exits in a node
23+
MaxCategoriesPerRouter = 100 // max number of categories a router can have
24+
)
25+
1926
// NodeUUID is a UUID of a flow node
2027
type NodeUUID uuids.UUID
2128

flows/routers/base.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ import (
1818
"github.com/nyaruka/goflow/utils"
1919
)
2020

21-
const (
22-
maxCategoriesPerRouter = 100 // max number of categories a router can have
23-
)
24-
2521
var registeredTypes = map[string](func() flows.Router){}
2622

2723
// registers a new type of router
@@ -95,8 +91,8 @@ func (r *baseRouter) EnumerateLocalizables(include func(uuids.UUID, string, []st
9591
}
9692

9793
func (r *baseRouter) validate(flow flows.Flow, exits []flows.Exit) error {
98-
if len(r.categories) > maxCategoriesPerRouter {
99-
return fmt.Errorf("router can't have more than %d categories", maxCategoriesPerRouter)
94+
if len(r.categories) > flows.MaxCategoriesPerRouter {
95+
return fmt.Errorf("router can't have more than %d categories (has %d)", flows.MaxCategoriesPerRouter, len(r.categories))
10096
}
10197

10298
// check wait timeout category is valid

0 commit comments

Comments
 (0)