Skip to content

Commit

Permalink
Fix panic on backup call if the SpiceDB version is unsupported
Browse files Browse the repository at this point in the history
  • Loading branch information
josephschorr committed Dec 5, 2023
1 parent 97172df commit 6e62b42
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func backupCmdFunc(cmd *cobra.Command, args []string) error {
hasProgressbar = true
}

if schemaResp.ReadAt == nil {
return fmt.Errorf("`backup` is not supported on this version of SpiceDB")
}

encoder, err := backupformat.NewEncoder(relWriter, schemaResp.SchemaText, schemaResp.ReadAt)
if err != nil {
return fmt.Errorf("error creating backup file encoder: %w", err)
Expand Down
5 changes: 5 additions & 0 deletions pkg/backupformat/encoder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package backupformat

import (
"errors"
"fmt"
"io"

Expand All @@ -15,6 +16,10 @@ func NewEncoder(w io.Writer, schema string, token *v1.ZedToken) (*Encoder, error
return nil, fmt.Errorf("unable to create avro schema: %w", err)
}

if token == nil {
return nil, errors.New("missing expected token")
}

md := map[string][]byte{
metadataKeyZT: []byte(token.Token),
}
Expand Down

0 comments on commit 6e62b42

Please sign in to comment.