File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -111,6 +111,11 @@ func (m *subscriptionManager) AddSubscription(
111
111
"subscription" : subscription .ID ,
112
112
}).Info ("Add subscription" )
113
113
114
+ if errors := validateSubscription (subscription ); len (errors ) > 0 {
115
+ m .logger .WithField ("errors" , errors ).Warn ("Failed to add invalid subscription" )
116
+ return errors
117
+ }
118
+
114
119
// Parse the subscription query
115
120
document , err := parser .Parse (parser.ParseParams {
116
121
Source : subscription .Query ,
@@ -184,3 +189,25 @@ func (m *subscriptionManager) RemoveSubscriptions(conn Connection) {
184
189
delete (m .subscriptions , conn )
185
190
}
186
191
}
192
+
193
+ func validateSubscription (s * Subscription ) []error {
194
+ errs := []error {}
195
+
196
+ if s .ID == "" {
197
+ errs = append (errs , errors .New ("Subscription ID is empty" ))
198
+ }
199
+
200
+ if s .Connection == nil {
201
+ errs = append (errs , errors .New ("Subscription is not associated with a connection" ))
202
+ }
203
+
204
+ if s .Query == "" {
205
+ errs = append (errs , errors .New ("Subscription query is empty" ))
206
+ }
207
+
208
+ if s .SendData == nil {
209
+ errs = append (errs , errors .New ("Subscription has no SendData function set" ))
210
+ }
211
+
212
+ return errs
213
+ }
You can’t perform that action at this time.
0 commit comments