Skip to content

Commit

Permalink
show fullname in enum error
Browse files Browse the repository at this point in the history
  • Loading branch information
ubunatic committed Jun 3, 2024
1 parent bfc1fc2 commit 072cb6e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 27 deletions.
51 changes: 27 additions & 24 deletions encoding/protobq/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,23 @@ func Test_Integration_PublicDataSets(t *testing.T) {
Message: &publicv1.FilmLocation{},
},

{
ProjectID: "bigquery-public-data",
DatasetID: "hacker_news",
TableID: "stories",
Limit: 10,
Message: &publicv1.HackerNewsStory{},
},
// no longer accessible
// {
// ProjectID: "bigquery-public-data",
// DatasetID: "hacker_news",
// TableID: "stories",
// Limit: 10,
// Message: &publicv1.HackerNewsStory{},
// },

{
ProjectID: "bigquery-public-data",
DatasetID: "london_bicycles",
TableID: "cycle_hire",
Limit: 10,
Message: &publicv1.LondonBicycleRental{},
},
// no longer accessible
// {
// ProjectID: "bigquery-public-data",
// DatasetID: "london_bicycles",
// TableID: "cycle_hire",
// Limit: 10,
// Message: &publicv1.LondonBicycleRental{},
// },

{
ProjectID: "bigquery-public-data",
Expand All @@ -65,16 +67,17 @@ func Test_Integration_PublicDataSets(t *testing.T) {
Message: &publicv1.SanFransiscoTransitStopTime{},
},

{
ProjectID: "bigquery-public-data",
DatasetID: "london_bicycles",
TableID: "cycle_stations",
Limit: 10,
Message: &publicv1.LondonBicycleStation{},
UnmarshalOptions: protobq.UnmarshalOptions{
DiscardUnknown: true, // Ignore non-snake case field "nbEmptyDocks".
},
},
// no longer accessible
// {
// ProjectID: "bigquery-public-data",
// DatasetID: "london_bicycles",
// TableID: "cycle_stations",
// Limit: 10,
// Message: &publicv1.LondonBicycleStation{},
// UnmarshalOptions: protobq.UnmarshalOptions{
// DiscardUnknown: true, // Ignore non-snake case field "nbEmptyDocks".
// },
// },

{
ProjectID: "bigquery-public-data",
Expand Down
3 changes: 2 additions & 1 deletion encoding/protobq/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ func (o MarshalOptions) marshalEnumValue(
// Use 'null' for BQ rows to indicate that no value could be determined.
return nil, nil
}
return nil, fmt.Errorf("unknown enum number: %v", value.Enum())
path := fmt.Sprintf("%s.%s", field.Parent().FullName(), field.Name())
return nil, fmt.Errorf("unknown enum number: %v, fieldname: %v", value.Enum(), path)
}

func (o MarshalOptions) marshalWellKnownTypeValue(
Expand Down
18 changes: 16 additions & 2 deletions encoding/protobq/marshal_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package protobq

import (
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -380,12 +381,25 @@ func TestMarshalOptions_Marshal(t *testing.T) {
"enum_value": nil,
},
},
{
name: "disallow unknown enum values",
msg: &examplev1.ExampleEnum{
EnumValue: examplev1.ExampleEnum_Enum(100),
},
opt: MarshalOptions{Schema: SchemaOptions{UseOneofFields: true}, DiscardUnknownEnumValues: false},
expected: nil,
},
} {
tt := tt
t.Run(tt.name, func(t *testing.T) {
actual, err := tt.opt.Marshal(tt.msg)
assert.NilError(t, err)
assert.DeepEqual(t, tt.expected, actual)
if tt.expected == nil {
fmt.Println(err)
assert.Error(t, err, "unknown enum number: 100, fieldname: einride.bigquery.example.v1.ExampleEnum.enum_value")
} else {
assert.NilError(t, err)
assert.DeepEqual(t, tt.expected, actual)
}
})
}
}

0 comments on commit 072cb6e

Please sign in to comment.