Skip to content

Commit

Permalink
chore: better errors on errors in cluster startup (#3879)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvmakine authored Jan 1, 2025
1 parent 0b7a691 commit 16d7c18
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions internal/raft/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ type ShardHandle[E Event, Q any, R any] struct {

// Propose an event to the shard.
func (s *ShardHandle[E, Q, R]) Propose(ctx context.Context, msg E) error {
if s.cluster.nh == nil {
panic("cluster not started")
}
s.verifyReady()

msgBytes, err := msg.MarshalBinary()
if err != nil {
Expand All @@ -113,9 +111,7 @@ func (s *ShardHandle[E, Q, R]) Propose(ctx context.Context, msg E) error {

// Query the state of the shard.
func (s *ShardHandle[E, Q, R]) Query(ctx context.Context, query Q) (R, error) {
if s.cluster.nh == nil {
panic("cluster not started")
}
s.verifyReady()

var zero R

Expand All @@ -132,6 +128,15 @@ func (s *ShardHandle[E, Q, R]) Query(ctx context.Context, query Q) (R, error) {
return response, nil
}

func (s *ShardHandle[E, Q, R]) verifyReady() {
if s.cluster == nil {
panic("cluster not built")
}
if s.cluster.nh == nil {
panic("cluster not started")
}
}

// Start the cluster. Blocks until the cluster instance is ready.
func (c *Cluster) Start(ctx context.Context) error {
return c.start(ctx, false)
Expand Down

0 comments on commit 16d7c18

Please sign in to comment.