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!: profile query returns nil if profile does not exist #971

Merged
merged 5 commits into from
Jul 22, 2022

Conversation

dadamu
Copy link
Contributor

@dadamu dadamu commented Jul 21, 2022

Description

Currently, querying a non-existing profile returns nil instead of error with profile not found for address/dtag.
This PR fixes the response of Profile behavior mentioned above.


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)

@github-actions github-actions bot added the x/profiles Module that allows to create and manage decentralized social profiles label Jul 21, 2022
@@ -47,7 +47,7 @@ func (k Keeper) Profile(ctx context.Context, request *types.QueryProfileRequest)
}

if !found {
return &types.QueryProfileResponse{Profile: nil}, nil
return nil, status.Errorf(codes.NotFound, "profile for dtag/address %s not found", dTagOrAddress)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is something I've thought about for a while, and honestly I don't remember why we chose to return nil instead of an error. However, I would like to take this chance to start a conversation about this. Particularly, I'm interested in knowing your opinion about the pros and cons that returning an error instead of nil might have.

I would like to ask you guys (@dadamu, @bragaz, @manu0466) considering your experience in smart contract development, as well as @ale-mazz considering his experience in client-side development. Do you think that a missing profile should return an error or null, and why?

Copy link
Contributor Author

@dadamu dadamu Jul 21, 2022

Choose a reason for hiding this comment

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

This issue is found during devloping the POAP-manager contract.

  1. If it returns nil, the contract side need to handle the Option unwrap process like:
let profile_res = ProfilesQuerier::new(deps.querier.deref()).query_profile(user)?;
match profile_res.profile {
    Some(profile) => Ok(operate(profile)),
    None => Err(some error)
}
  1. If it returns an error, then the process can be simplified to be as follow since the non found profile case has been already handled by error:
let profile_res = ProfilesQuerier::new(deps.querier.deref()).query_profile(user)?;
operate(profile_res.profile)

Besides, frontend also need a check if the profile exists or not if it returns nil.
As a result, I would use returning error instead if the specific item does not exist.

Copy link
Contributor

Choose a reason for hiding this comment

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

In my opinion, it would be more correct to return an error, so the frontend developer would have an advantage in relaunching the error in the UI or handling it in the way they prefer. Returning null might lead one to think of the presence of a possible backend error or otherwise something incorrect. I always consider error handling rather than returning null, undefined, etc. values to be superior.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok thanks for the contributions. I think the best thing for clients then is to simply return nil so I will accept this PR as soon as @dadamu adds the proper changeset entry.

@github-actions github-actions bot added the x/CLI label Jul 21, 2022
@codecov
Copy link

codecov bot commented Jul 21, 2022

Codecov Report

Merging #971 (d68c4ea) into master (c7ff50d) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #971      +/-   ##
==========================================
- Coverage   80.54%   80.50%   -0.04%     
==========================================
  Files         172      172              
  Lines       15095    15223     +128     
==========================================
+ Hits        12158    12256      +98     
- Misses       2415     2440      +25     
- Partials      522      527       +5     
Impacted Files Coverage Δ
x/profiles/keeper/grpc_query.go 79.51% <100.00%> (ø)
x/profiles/types/models_chain_links.go 74.28% <0.00%> (-2.86%) ⬇️
x/profiles/types/codec.go 100.00% <0.00%> (ø)
x/profiles/client/cli/cli_profile.go 86.20% <0.00%> (+3.44%) ⬆️
x/profiles/legacy/v6/store.go 67.55% <0.00%> (+4.44%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c7ff50d...d68c4ea. Read the comment docs.

Copy link
Contributor

@RiccardoM RiccardoM left a comment

Choose a reason for hiding this comment

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

Please add a changeset entry as this is a breaking change that clients need to be aware of

@RiccardoM RiccardoM changed the title fix: fix profile query if it does not exist fix!: profile query returns nil if profile does not exist Jul 22, 2022
@dadamu dadamu requested a review from RiccardoM July 22, 2022 06:28
@dadamu
Copy link
Contributor Author

dadamu commented Jul 22, 2022

@RiccardoM Added.

@RiccardoM RiccardoM added the automerge Automatically merge PR once all prerequisites pass label Jul 22, 2022
@RiccardoM RiccardoM merged commit 95711e2 into master Jul 22, 2022
@RiccardoM RiccardoM deleted the paul/fix-profile-query branch July 22, 2022 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Automatically merge PR once all prerequisites pass x/CLI x/profiles Module that allows to create and manage decentralized social profiles
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants