This repository has been archived by the owner on Oct 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
compiler_errors.go
executable file
·272 lines (223 loc) · 7.2 KB
/
compiler_errors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
package errors
import (
"fmt"
"runtime"
"strings"
)
const (
// A cycle is detected in the Workflow, the error description should detail the nodes involved.
CycleDetected ErrorCode = "CycleDetected"
// BranchNode is missing a case with ThenNode populated.
BranchNodeIDNotFound ErrorCode = "BranchNodeIdNotFound"
// BranchNode is missing a condition.
BranchNodeHasNoCondition ErrorCode = "BranchNodeHasNoCondition"
// An expected field isn't populated.
ValueRequired ErrorCode = "ValueRequired"
// A nodeBuilder referenced by an edge doesn't belong to the Workflow.
NodeReferenceNotFound ErrorCode = "NodeReferenceNotFound"
// A Task referenced by a node wasn't found.
TaskReferenceNotFound ErrorCode = "TaskReferenceNotFound"
// A Workflow referenced by a node wasn't found.
WorkflowReferenceNotFound ErrorCode = "WorkflowReferenceNotFound"
// A referenced variable (in a parameter or a condition) wasn't found.
VariableNameNotFound ErrorCode = "VariableNameNotFound"
// An alias existed twice.
DuplicateAlias ErrorCode = "DuplicateAlias"
// An Id existed twice.
DuplicateNodeID ErrorCode = "DuplicateId"
// Two types expected to be compatible but aren't.
MismatchingTypes ErrorCode = "MismatchingTypes"
// A binding is attempted via a list or map syntax, but the underlying type isn't a list or map.
MismatchingBindings ErrorCode = "MismatchingBindings"
// Two interfaced expected to be compatible but aren't.
MismatchingInterfaces ErrorCode = "MismatchingInterfaces"
// Expected types to be consistent.
InconsistentTypes ErrorCode = "InconsistentTypes"
// An input/output parameter was assigned a value through an edge more than once.
ParameterBoundMoreThanOnce ErrorCode = "ParameterBoundMoreThanOnce"
// One of the required input parameters or a Workflow output parameter wasn't bound.
ParameterNotBound ErrorCode = "ParameterNotBound"
// When we couldn't assign an entry point to the Workflow.
NoEntryNodeFound ErrorCode = "NoEntryNodeFound"
// When one more more unreachable node are detected.
UnreachableNodes ErrorCode = "UnreachableNodes"
// A Value doesn't fall within the expected range.
UnrecognizedValue ErrorCode = "UnrecognizedValue"
// An unknown error occurred while building the workflow.
WorkflowBuildError ErrorCode = "WorkflowBuildError"
// A value is expected to be unique but wasnt.
ValueCollision ErrorCode = "ValueCollision"
// A value isn't on the right syntax.
SyntaxError ErrorCode = "SyntaxError"
)
func NewBranchNodeNotSpecified(branchNodeID string) *CompileError {
return newError(
BranchNodeIDNotFound,
fmt.Sprintf("BranchNode not assigned"),
branchNodeID,
)
}
func NewBranchNodeHasNoCondition(branchNodeID string) *CompileError {
return newError(
BranchNodeHasNoCondition,
"One of the branches on the node doesn't have a condition.",
branchNodeID,
)
}
func NewValueRequiredErr(nodeID, paramName string) *CompileError {
return newError(
ValueRequired,
fmt.Sprintf("Value required [%v].", paramName),
nodeID,
)
}
func NewParameterNotBoundErr(nodeID, paramName string) *CompileError {
return newError(
ParameterNotBound,
fmt.Sprintf("Parameter not bound [%v].", paramName),
nodeID,
)
}
func NewNodeReferenceNotFoundErr(nodeID, referenceID string) *CompileError {
return newError(
NodeReferenceNotFound,
fmt.Sprintf("Referenced node [%v] not found.", referenceID),
nodeID,
)
}
func NewWorkflowReferenceNotFoundErr(nodeID, referenceID string) *CompileError {
return newError(
WorkflowReferenceNotFound,
fmt.Sprintf("Referenced Workflow [%v] not found.", referenceID),
nodeID,
)
}
func NewTaskReferenceNotFoundErr(nodeID, referenceID string) *CompileError {
return newError(
TaskReferenceNotFound,
fmt.Sprintf("Referenced Task [%v] not found.", referenceID),
nodeID,
)
}
func NewVariableNameNotFoundErr(nodeID, referenceID, variableName string) *CompileError {
return newError(
VariableNameNotFound,
fmt.Sprintf("Variable [%v] not found on node [%v].", variableName, referenceID),
nodeID,
)
}
func NewParameterBoundMoreThanOnceErr(nodeID, paramName string) *CompileError {
return newError(
ParameterBoundMoreThanOnce,
fmt.Sprintf("Input [%v] is bound more than once.", paramName),
nodeID,
)
}
func NewDuplicateAliasErr(nodeID, alias string) *CompileError {
return newError(
DuplicateAlias,
fmt.Sprintf("Duplicate alias [%v] found. An output alias can only be used once in the Workflow.", alias),
nodeID,
)
}
func NewDuplicateIDFoundErr(nodeID string) *CompileError {
return newError(
DuplicateNodeID,
"Trying to insert two nodes with the same id.",
nodeID,
)
}
func NewMismatchingTypesErr(nodeID, fromVar, fromType, toType string) *CompileError {
return newError(
MismatchingTypes,
fmt.Sprintf("Variable [%v] (type [%v]) doesn't match expected type [%v].", fromVar, fromType,
toType),
nodeID,
)
}
func NewMismatchingBindingsErr(nodeID, sinkParam, expectedType, receivedType string) *CompileError {
return newError(
MismatchingBindings,
fmt.Sprintf("Input [%v] on node [%v] expects bindings of type [%v]. Received [%v]", sinkParam, nodeID, expectedType, receivedType),
nodeID,
)
}
func NewMismatchingInterfacesErr(nodeID1, nodeID2 string) *CompileError {
return newError(
MismatchingInterfaces,
fmt.Sprintf("Interfaces of nodes [%v] and [%v] do not match.", nodeID1, nodeID2),
nodeID1,
)
}
func NewInconsistentTypesErr(nodeID, expectedType, actualType string) *CompileError {
return newError(
InconsistentTypes,
fmt.Sprintf("Expected type: %v but found %v", expectedType, actualType),
nodeID,
)
}
func NewWorkflowHasNoEntryNodeErr(graphID string) *CompileError {
return newError(
NoEntryNodeFound,
fmt.Sprintf("Can't find a node to start executing Workflow [%v].", graphID),
graphID,
)
}
func NewCycleDetectedInWorkflowErr(nodeID, cycle string) *CompileError {
return newError(
CycleDetected,
fmt.Sprintf("A cycle has been detected while traversing the Workflow [%v].", cycle),
nodeID,
)
}
func NewUnreachableNodesErr(nodeID, nodes string) *CompileError {
return newError(
UnreachableNodes,
fmt.Sprintf("The Workflow contain unreachable nodes [%v].", nodes),
nodeID,
)
}
func NewUnrecognizedValueErr(nodeID, value string) *CompileError {
return newError(
UnrecognizedValue,
fmt.Sprintf("Unrecognized value [%v].", value),
nodeID,
)
}
func NewWorkflowBuildError(err error) *CompileError {
return newError(WorkflowBuildError, err.Error(), "")
}
func NewValueCollisionError(nodeID string, valueName, value string) *CompileError {
return newError(
ValueCollision,
fmt.Sprintf("%v is expected to be unique. %v already exists.", valueName, value),
nodeID,
)
}
func NewSyntaxError(nodeID string, element string, err error) *CompileError {
return newError(SyntaxError,
fmt.Sprintf("Failed to parse element [%v].", element),
nodeID,
)
}
func newError(code ErrorCode, description, nodeID string) (err *CompileError) {
err = &CompileError{
code: code,
description: description,
nodeID: nodeID,
}
if GetConfig().IncludeSource {
_, file, line, ok := runtime.Caller(2)
if !ok {
file = "???"
line = 1
} else {
slash := strings.LastIndex(file, "/")
if slash >= 0 {
file = file[slash+1:]
}
}
err.source = fmt.Sprintf("%v:%v", file, line)
}
return
}