diff --git a/go/libraries/doltcore/schema/encoding/schema_marshaling.go b/go/libraries/doltcore/schema/encoding/schema_marshaling.go index 4cd078f48a..4644386c85 100644 --- a/go/libraries/doltcore/schema/encoding/schema_marshaling.go +++ b/go/libraries/doltcore/schema/encoding/schema_marshaling.go @@ -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 { diff --git a/go/libraries/doltcore/schema/encoding/schema_marshaling_test.go b/go/libraries/doltcore/schema/encoding/schema_marshaling_test.go index 7358775e00..86561ff128 100644 --- a/go/libraries/doltcore/schema/encoding/schema_marshaling_test.go +++ b/go/libraries/doltcore/schema/encoding/schema_marshaling_test.go @@ -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)