Don't panic when unmarshelling a schema with missing chunks

This commit is contained in:
Neil Macneale IV
2025-12-11 15:32:13 -08:00
parent 932a808cad
commit 51438ed4e0
2 changed files with 11 additions and 0 deletions

View File

@@ -466,6 +466,9 @@ func UnmarshalSchemaAtAddr(ctx context.Context, vr types.ValueReader, addr hash.
if err != nil {
return nil, err
}
if schemaVal == nil {
return nil, fmt.Errorf("database malformed: no schema found at address %s", addr.String())
}
sch, err := UnmarshalSchema(ctx, vr.Format(), schemaVal)
if err != nil {

View File

@@ -22,6 +22,7 @@ import (
"strconv"
"testing"
"github.com/dolthub/dolt/go/store/hash"
"github.com/dolthub/go-mysql-server/sql"
gmstypes "github.com/dolthub/go-mysql-server/sql/types"
"github.com/dolthub/vitess/go/sqltypes"
@@ -51,6 +52,13 @@ func createTestSchema() schema.Schema {
return sch
}
func TestSchemaUnmarshal(t *testing.T) {
_, vrw, _, err := dbfactory.MemFactory{}.CreateDB(context.Background(), types.Format_Default, nil, nil)
val, err := UnmarshalSchemaAtAddr(context.Background(), vrw, hash.Parse("badaddrvvvvvvvvvvvvvvvvvvvvvvvvv"))
require.Error(t, err)
require.Nil(t, val)
}
func TestNomsMarshalling(t *testing.T) {
tSchema := createTestSchema()
_, vrw, _, err := dbfactory.MemFactory{}.CreateDB(context.Background(), types.Format_Default, nil, nil)