Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix panic on backup call if the SpiceDB version is unsupported #312

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading