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

Return encode decode errors grpc #2952

Merged
merged 3 commits into from
Nov 30, 2021
Merged

Conversation

nitinmohan87
Copy link
Contributor

Without this change, goa returns a "fault" error from server even when the error was client side (e.g., goa request validation failed).

This PR makes sure that we return any validation errors during encode/decode as it is without changing them to grpc errors. I have also exported Goa's encode/decode error names so that it can be used in the design for mapping error name to a status code of choice.

NOTE: This is a breaking change because

  • it changes the error name from "fault" to the actual error name that happened during encode/decode.
  • it changes the grpc status code to "Unknown" instead of "InvalidArgument" unless the corresponding encode/decode error is mapped to a code of choice in the design (see example below)
Error(goa.InvalidLength)
GRPC(func() {
    Response(goa.InvalidLength, CodeInvalidArgument)
})

@raphael
Copy link
Member

raphael commented Nov 29, 2021

Thank you for the PR, looks great! Just one suggestion: could we also add the error constants to the DSL package so that they can be properly documented? The definitions could alias the ones in the pkg package. So in dsl/error.go there could be:

const (
	// The constants below make it possible for the service specific code to
	// return error names that are consistent with the names used by the
	// generated request and response payload validation code.
	// Usage:
	// [Provide meaningful example here]

	// InvalidFieldType is the error name for invalid field type errors.
	InvalidFieldType = pkg.InvalidFieldType
	// MissingField is the error name for missing field errors.
	MissingField = ...
)

@raphael
Copy link
Member

raphael commented Nov 30, 2021

Thank you!

@raphael raphael merged commit 11ba88a into v3 Nov 30, 2021
@raphael raphael deleted the return_encode_decode_errors_grpc branch November 30, 2021 21:15
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.

2 participants