From 6e62b4248403b6ee12dc943ca3725f5188082a8e Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Tue, 5 Dec 2023 18:14:56 -0500 Subject: [PATCH] Fix panic on backup call if the SpiceDB version is unsupported --- internal/cmd/backup.go | 4 ++++ pkg/backupformat/encoder.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/internal/cmd/backup.go b/internal/cmd/backup.go index 9ff6a30c..28bf91f7 100644 --- a/internal/cmd/backup.go +++ b/internal/cmd/backup.go @@ -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) diff --git a/pkg/backupformat/encoder.go b/pkg/backupformat/encoder.go index b892dda8..60eb42f5 100644 --- a/pkg/backupformat/encoder.go +++ b/pkg/backupformat/encoder.go @@ -1,6 +1,7 @@ package backupformat import ( + "errors" "fmt" "io" @@ -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), }