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

fix: use ctx.Codec when marshaling for generated batch json in CLI #514

Merged
merged 6 commits into from
Sep 4, 2021

Conversation

clevinson
Copy link
Member

@clevinson clevinson commented Sep 2, 2021

Description

When reviewing #513 I noticed that we weren't using the ctx.Codec's JSON marshaler for generating batch JSON. This is a pretty minor thing, but I figured it's good practice for us to use the same serializer as we use across other parts of the SDK, especially as we may be making use of jsonpb's configuration to serialize using the original field names (independent of explicit JSON field names defined in the proto file).

I could have written this up in an issue, but figured it'd be easier to just put in a fix. Happy to re-evaluate this decision if I'm missing some reason why we were using the standard json package before.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@clevinson clevinson added the Scope: x/ecocredit Issues that update the x/ecocredit module label Sep 2, 2021
@@ -16,7 +16,7 @@ var reLocation = regexp.MustCompile(`^([A-Z]{2})(?:-([A-Z0-9]{1,3})(?: ([a-zA-Z0
func validateLocation(location string) error {
matches := reLocation.FindStringSubmatch(location)
if matches == nil {
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid retirement location: %s.\nLocation should have format <country-code>[-<region-code>[ <postal-code>]].\n", location)
return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "Invalid location: %s.\nLocation should have format <country-code>[-<region-code>[ <postal-code>]].\n", location)
Copy link
Member Author

Choose a reason for hiding this comment

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

This error gets thrown sometimes for an invalid project_location, so I updated this to make it generic to project and/or retirement location.

Copy link
Contributor

Choose a reason for hiding this comment

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

looks like a few test cases need to be updated for this

"start_date": "1990-01-01",
"end_date": "1995-10-31",
"project_location": "AB-CDE FG1 345",
}
Copy link
Member Author

Choose a reason for hiding this comment

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

the Long help text argument doesn't have access to the *cobra.Command, so its not possible to retrieve the sdkcontext and the JSON marshaler... So I hardcoded an example JSON help text here.

Copy link
Contributor

@ruhatch ruhatch left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @clevinson

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm

@ruhatch ruhatch enabled auto-merge (squash) September 4, 2021 09:35
@ruhatch ruhatch merged commit 1a38fb0 into master Sep 4, 2021
@ruhatch ruhatch deleted the clevinson/gen-batch-fix branch September 4, 2021 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: x/ecocredit Issues that update the x/ecocredit module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants