Skip to content

Commit

Permalink
fix panic on early exit
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Oct 7, 2024
1 parent d7ab5bd commit 757a7aa
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions backend/controller/admin/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"context"
"fmt"

"github.com/alecthomas/types/either"
"github.com/alecthomas/types/optional"

"github.com/TBD54566975/ftl/internal/buildengine/languageplugin"
cf "github.com/TBD54566975/ftl/internal/configuration"
"github.com/TBD54566975/ftl/internal/configuration/manager"
"github.com/TBD54566975/ftl/internal/errors"
"github.com/TBD54566975/ftl/internal/projectconfig"
"github.com/TBD54566975/ftl/internal/schema"
"github.com/TBD54566975/ftl/internal/watch"
"github.com/alecthomas/types/either"
"github.com/alecthomas/types/optional"
)

// localClient reads and writes to local projectconfig files without making any network
Expand Down Expand Up @@ -46,7 +46,7 @@ func (s *diskSchemaRetriever) GetActiveSchema(ctx context.Context) (*schema.Sche
return nil, fmt.Errorf("could not discover modules: %w", err)
}

moduleSchemas := make(chan either.Either[*schema.Module, error], len(modules))
moduleSchemas := make(chan either.Either[*schema.Module, error], 32)
defer close(moduleSchemas)

for _, m := range modules {
Expand Down Expand Up @@ -76,17 +76,20 @@ func (s *diskSchemaRetriever) GetActiveSchema(ctx context.Context) (*schema.Sche
}()
}
sch := &schema.Schema{}
errs := []error{}
for range len(modules) {
result := <-moduleSchemas
switch result := result.(type) {
case either.Left[*schema.Module, error]:
sch.Upsert(result.Get())
case either.Right[*schema.Module, error]:
return nil, result.Get()
errs = append(errs, result.Get())
default:
panic(fmt.Sprintf("unexpected type %T", result))

}
}
if len(errs) > 0 {
return nil, errors.Join(errs...)
}
return sch, nil
}

0 comments on commit 757a7aa

Please sign in to comment.