diff --git a/spanner/read_test.go b/spanner/read_test.go index 5c1e74a1af5..480df6c5254 100644 --- a/spanner/read_test.go +++ b/spanner/read_test.go @@ -152,11 +152,6 @@ var ( } ) -// String implements fmt.stringer. -func (r *Row) String() string { - return fmt.Sprintf("{fields: %s, val: %s}", r.fields, r.vals) -} - func describeRows(l []*Row) string { // generate a nice test failure description var s = "[" diff --git a/spanner/row.go b/spanner/row.go index 8097031e2de..c5c37430f2e 100644 --- a/spanner/row.go +++ b/spanner/row.go @@ -88,6 +88,11 @@ type Row struct { vals []*proto3.Value // keep decoded for now } +// String implements fmt.stringer. +func (r *Row) String() string { + return fmt.Sprintf("{fields: %s, values: %s}", r.fields, r.vals) +} + // errNamesValuesMismatch returns error for when columnNames count is not equal // to columnValues count. func errNamesValuesMismatch(columnNames []string, columnValues []interface{}) error { diff --git a/spanner/row_test.go b/spanner/row_test.go index d909297bc5b..a27d758fa6f 100644 --- a/spanner/row_test.go +++ b/spanner/row_test.go @@ -1672,6 +1672,24 @@ func TestToStructEmbedded(t *testing.T) { } } +func TestRowToString(t *testing.T) { + r := Row{ + []*sppb.StructType_Field{ + {Name: "F1", Type: stringType()}, + {Name: "F2", Type: stringType()}, + }, + []*proto3.Value{ + stringProto("v1"), + stringProto("v2"), + }, + } + got := r.String() + want := `{fields: [name:"F1" type:{code:STRING} name:"F2" type:{code:STRING}], values: [string_value:"v1" string_value:"v2"]}` + if !testEqual(r.String(), want) { + t.Errorf("got %+v, want %+v", got, want) + } +} + // Test helpers for getting column names. func TestColumnNameAndIndex(t *testing.T) { // Test Row.Size(). diff --git a/spanner/value.go b/spanner/value.go index 46a118f1fcb..7a2a4033192 100644 --- a/spanner/value.go +++ b/spanner/value.go @@ -1355,8 +1355,8 @@ func decodeValue(v *proto3.Value, t *sppb.Type, ptr interface{}) error { return errNilDst(p) } if !isPtrStructPtrSlice(vp.Type()) { - // The container is not a pointer to a struct pointer slice. - return errTypeMismatch(code, acode, ptr) + // The container is not a slice of struct pointers. + return fmt.Errorf("the container is not a slice of struct pointers: %v", errTypeMismatch(code, acode, ptr)) } // Only use reflection for nil detection on slow path. // Also, IsNil panics on many types, so check it after the type check.