Skip to content

Commit e53d952

Browse files
authored
feat: Provide User with actionable error message when no tables are configured for syncing (#1243)
<!-- Explain what problem this PR addresses --> ---
1 parent 41c15cf commit e53d952

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

scheduler/scheduler.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const (
3131
otelName = "schedule"
3232
)
3333

34+
var ErrNoTables = errors.New("no tables specified for syncing, review `tables` and `skip_tables` in your config and specify at least one table to sync")
35+
3436
const (
3537
StrategyDFS Strategy = iota
3638
StrategyRoundRobin
@@ -219,7 +221,7 @@ func (s *Scheduler) Sync(ctx context.Context, client schema.ClientMeta, tables s
219221
ctx, span := otel.Tracer(otelName).Start(ctx, "Sync")
220222
defer span.End()
221223
if len(tables) == 0 {
222-
return nil
224+
return ErrNoTables
223225
}
224226

225227
syncClient := &syncClient{

scheduler/scheduler_test.go

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ func testTableResolverPanic() *schema.Table {
8080
}
8181
}
8282

83+
func testNoTables() *schema.Table {
84+
return nil
85+
}
86+
8387
func testTablePreResourceResolverPanic() *schema.Table {
8488
return &schema.Table{
8589
Name: "test_table_pre_resource_resolver_panic",
@@ -132,6 +136,7 @@ type syncTestCase struct {
132136
table *schema.Table
133137
data []scalar.Vector
134138
deterministicCQID bool
139+
err error
135140
}
136141

137142
var syncTestCases = []syncTestCase{
@@ -152,6 +157,12 @@ var syncTestCases = []syncTestCase{
152157
data: nil,
153158
},
154159

160+
{
161+
table: testNoTables(),
162+
data: nil,
163+
err: ErrNoTables,
164+
},
165+
155166
{
156167
table: testTableRelationSuccess(),
157168
data: []scalar.Vector{
@@ -210,8 +221,12 @@ func TestScheduler(t *testing.T) {
210221
for _, strategy := range AllStrategies {
211222
for _, tc := range syncTestCases {
212223
tc := tc
213-
tc.table = tc.table.Copy(nil)
214-
t.Run(tc.table.Name+"_"+strategy.String(), func(t *testing.T) {
224+
testName := "No table_" + strategy.String()
225+
if tc.table != nil {
226+
tc.table = tc.table.Copy(nil)
227+
testName = tc.table.Name + "_" + strategy.String()
228+
}
229+
t.Run(testName, func(t *testing.T) {
215230
testSyncTable(t, tc, strategy, tc.deterministicCQID)
216231
})
217232
}
@@ -220,8 +235,9 @@ func TestScheduler(t *testing.T) {
220235

221236
func testSyncTable(t *testing.T, tc syncTestCase, strategy Strategy, deterministicCQID bool) {
222237
ctx := context.Background()
223-
tables := []*schema.Table{
224-
tc.table,
238+
tables := []*schema.Table{}
239+
if tc.table != nil {
240+
tables = append(tables, tc.table)
225241
}
226242
c := testExecutionClient{}
227243
opts := []Option{
@@ -230,7 +246,8 @@ func testSyncTable(t *testing.T, tc syncTestCase, strategy Strategy, determinist
230246
}
231247
sc := NewScheduler(opts...)
232248
msgs := make(chan message.SyncMessage, 10)
233-
if err := sc.Sync(ctx, &c, tables, msgs, WithSyncDeterministicCQID(deterministicCQID)); err != nil {
249+
err := sc.Sync(ctx, &c, tables, msgs, WithSyncDeterministicCQID(deterministicCQID))
250+
if err != tc.err {
234251
t.Fatal(err)
235252
}
236253
close(msgs)

0 commit comments

Comments
 (0)