Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error handling google.protobuf.Timestamp #3

Open
catherinetcai opened this issue Nov 21, 2017 · 5 comments
Open

Error handling google.protobuf.Timestamp #3

catherinetcai opened this issue Nov 21, 2017 · 5 comments

Comments

@catherinetcai
Copy link
Contributor

Message looks like this:

message MyMessage {
  // Some fields here
  google.protobuf.Timestamp time = 2;
}

When issuing request like so:

./gurl -u localhost:50051/<redacted>/<redacted> -d '{"time": { "seconds": 123 }}'

Getting error:

2017-11-21T13:11:09.688-0800	ERROR	grpc/validator.go:24	invalid syntax
go.uber.org/zap.Stack
	/Users/ccai/go/src/go.uber.org/zap/field.go:209
go.uber.org/zap.(*Logger).check
	/Users/ccai/go/src/go.uber.org/zap/logger.go:273
go.uber.org/zap.(*Logger).Error
	/Users/ccai/go/src/go.uber.org/zap/logger.go:176
github.com/wearefair/gurl/grpc.(*Validator).Validate
	/Users/ccai/go/src/github.com/wearefair/gurl/grpc/validator.go:24
github.com/wearefair/gurl/cmd.curl
	/Users/ccai/go/src/github.com/wearefair/gurl/cmd/root.go:90
github.com/spf13/cobra.(*Command).execute
	/Users/ccai/go/src/github.com/spf13/cobra/command.go:700
github.com/spf13/cobra.(*Command).ExecuteC
	/Users/ccai/go/src/github.com/spf13/cobra/command.go:785
github.com/spf13/cobra.(*Command).Execute
	/Users/ccai/go/src/github.com/spf13/cobra/command.go:738
github.com/wearefair/gurl/cmd.Execute
	/Users/ccai/go/src/github.com/wearefair/gurl/cmd/root.go:44
main.main
	/Users/ccai/go/src/github.com/wearefair/gurl/main.go:6
@catherinetcai
Copy link
Contributor Author

grpc/grpc#10304 could be related

@catherinetcai
Copy link
Contributor Author

catherinetcai commented Nov 25, 2017

Check to see if the fix appended at the end of the thread can be resolved via protoreflect's standard imports: https://github.com/jhump/protoreflect/blob/master/desc/protoparse/std_imports.go

golang/protobuf#414

The default protobuf jsonpb marshaler can handle Timestamp types - https://github.com/golang/protobuf/blob/master/jsonpb/jsonpb.go#L770 so figure out why it's not hitting that point...

@catherinetcai
Copy link
Contributor Author

catherinetcai commented Dec 3, 2017

Looks like this can be resolved as long as it's using the default format of JSON -> Proto (and vice versa) defined by JSON mapping.

This means requests have to look like this:

go run main.go -u localhost:50051/service.Name/method.Name -d '{"time": "1972-01-01T10:00:20.021Z" }'

Also, after further inspection of the Timestamp type (and implementing it), it seems like it hits here. It might actually be using something on protoreflect's side to handle unmarshaling. Worth further inspection here

@catherinetcai
Copy link
Contributor Author

Did a ton more digging.

Quite a few things are going to have to change if we decide to do a custom JSONPBUnmarshaler. It's really nasty.

All of the unmarshalling logic on the protoreflect side is going to have to swap to use the custom type, since it calls the jsonpb struct directly because it implements the JSONPBUnmarshaler interface. This is because underneath the covers, the jsonpb struct calls the proto's Unmarshal method first. The dynamic message's unmarshal json stuff wraps some of the logic around the dynamic message, then calls the original unmarshal method per field on the proto.

Anyway, here's where the current invalid syntax error is propagating from, because whatever's returned is not going to just be a string. (If curious, here's where the error is originating from).

@catherinetcai
Copy link
Contributor Author

Relabeling this as an enhancement and not a bug, since using the right format fixes this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant