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

status: move statusError to internal/status package #3432

Merged
merged 14 commits into from Apr 6, 2020

Conversation

JNProtzman
Copy link
Contributor

Fixes #3304

return fmt.Sprintf("rpc error: code = %s desc = %s", codes.Code(p.GetCode()), p.GetMessage())
}

func (se *StatusError) GRPCStatus() *spb.Status {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd imagine this change in public API may not be OK... Or it may since I'm moving this type to internal.

If I try to return a status.Status, I'll end up encountering an import cycle. @dfawley let me know what you think!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ARGH! Import cycles. Would something like this work?

grpc/internal/status/statustype/statustype.go:

package statustype

type Status struct {
// move grpc/status/status.Status here
}

// Constructors/getters
grpc/status/status.go:

package status

type Status = statustype.Status
grpc/internal/status/status.go:

package status

func (se *StatusError) GRPCStatus() *statustype.Status {
  ...
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, so I've tried this again - I run into an import cycle with statustype, because the Err() method returns a (*status.StatusError)(s.Proto()). If I make Status satisfy the error interface, the tests fail because of a type assertion to *status.StatusError.
Not sure of the right path forward!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, true. Status needs to reference StatusError and vice-versa. It's been awhile since I looked at this, but now I'm not sure why I was suggesting a third package at all. Can Status be defined in internal as well (in the same package as StatusError), with the same type alias from grpc/status for status.Status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I got that working! Tests pass (locally at least) so I'm muuuch more comfortable with this change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this looks good, thanks!

@dfawley dfawley closed this Mar 31, 2020
@dfawley dfawley reopened this Mar 31, 2020
internal/status/status.go Show resolved Hide resolved
status/status.go Outdated Show resolved Hide resolved
status/status.go Show resolved Hide resolved
internal/status/status.go Outdated Show resolved Hide resolved
Copy link
Member

@dfawley dfawley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good except the one go.mod file. Thanks!

internal/status/status.go Show resolved Hide resolved
@@ -2,4 +2,9 @@ module google.golang.org/grpc/security/advancedtls

go 1.13

require google.golang.org/grpc v1.27.0
require (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

status/status.go Show resolved Hide resolved
@JNProtzman JNProtzman requested a review from dfawley April 3, 2020 17:52
@JNProtzman
Copy link
Contributor Author

JNProtzman commented Apr 3, 2020

There's some go lint issues being reported by travis - do those need to be fixed before we can proceed?

@dfawley
Copy link
Member

dfawley commented Apr 3, 2020

Yes; they should be resolved.

internal/status/status.go:146:6: type name will be used as status.StatusError by other packages, and that stutters; consider calling this Error
internal/status/status.go:153:1: exported method StatusError.GRPCStatus should have comment or be unexported

status.Error SGTM and please add a comment as requested.

@dfawley dfawley changed the title Move StatusError to internal/status status: move statusError to internal/status package Apr 6, 2020
@dfawley dfawley merged commit c5faf56 into grpc:master Apr 6, 2020
@JNProtzman JNProtzman deleted the statusError branch April 6, 2020 19:07
@easwars easwars added this to the 1.29 Release milestone Apr 8, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move status.statusError to internal and export
4 participants