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

Unexport RESTCodec #94

Closed
wants to merge 1 commit into from
Closed

Unexport RESTCodec #94

wants to merge 1 commit into from

Conversation

jhump
Copy link
Member

@jhump jhump commented Oct 23, 2023

Comments now direct users to use vanguard.JSONCodec because of the add'l operations it provides. NewTranscoder now checks that the codec registered for "json" provides the needed methods if/when REST protocol is used.

@jhump jhump requested a review from emcfarlane October 23, 2023 21:16
codec := newCodec(protoregistry.GlobalTypes)
if _, supportsREST := codec.(restCodec); !supportsREST {
return nil, fmt.Errorf(
"configuration uses REST protocol but codec for %q format is does not support REST-specific operations: %T",
Copy link
Collaborator

@emcfarlane emcfarlane Oct 23, 2023

Choose a reason for hiding this comment

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

REST can still be used but marshalling maps, lists and single field JSON payloads cannot. This might be fine for most users. Error instead if needed via the interface cast?

Copy link
Member Author

Choose a reason for hiding this comment

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

That feels like over-fitting. If they encounter this error (already like to be extremely rare) and they don't actually need the add'l methods, they could easily implement them on their codec as no-ops that always return a error. I don't think we need to get too sophisticated for such an unlikely edge case.

Copy link
Collaborator

@emcfarlane emcfarlane Oct 23, 2023

Choose a reason for hiding this comment

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

My suggestion here was to remove this special case checking and just let it error if used. Less code. But fine either way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Surely over-fitting is forcing the user to care about the edge case without them first requiring it. Let the Codec interface cast error inform the user that it's required. I think it's weird to have a forced interface REST, via no-ops in methods as the solution, when the subset implemented by Codec would suffice.

Copy link
Member Author

@jhump jhump Oct 24, 2023

Choose a reason for hiding this comment

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

I don't agree. Ignoring likely configuration errors and letting them turn into runtime errors after the server has started taking traffic is a terrible operational experience.

@jhump jhump closed this Oct 24, 2023
@emcfarlane emcfarlane deleted the jh/remove-rest-codec branch October 26, 2023 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants