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

[context] tolerate empty candidate name #4562

Merged
merged 1 commit into from
Feb 24, 2025
Merged

[context] tolerate empty candidate name #4562

merged 1 commit into from
Feb 24, 2025

Conversation

dustinxie
Copy link
Member

Description

as title, fix the following bug.

Fixes #4561

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@dustinxie dustinxie marked this pull request as draft February 16, 2025 22:37
Comment on lines 40 to 44
fCtx := protocol.MustGetFeatureCtx(ctx)
for err := range errChan {
return errors.Wrap(err, "failed to validate action")
if !fCtx.Tolerate(err) {
return errors.Wrap(err, "failed to validate action")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

it is inexplicit to handle the error here.

if err = selp.Envelope.SanityCheck(); err != nil {

Copy link
Member Author

@dustinxie dustinxie Feb 18, 2025

Choose a reason for hiding this comment

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

fixed

Comment on lines +314 to +319
func (fCtx *FeatureCtx) Tolerate(err error) bool {
if fCtx.TolerateEmptyCandidateName && errors.Cause(err) == action.ErrInvalidCanName {
return true
}
return false
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

error type shouldn't not be included in a function which doesn't name it's functionality.

if err = selp.Envelope.SanityCheck(); err != nil {
is a better place to handle the check

Copy link
Member Author

@dustinxie dustinxie Feb 18, 2025

Choose a reason for hiding this comment

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

fixed

@dustinxie dustinxie marked this pull request as ready for review February 18, 2025 02:00
@@ -58,7 +58,8 @@ func (v *GenericValidator) Validate(ctx context.Context, selp *action.SealedEnve
if caller == nil {
return errors.New("failed to get address")
}
if err = selp.Envelope.SanityCheck(); err != nil {
featureCtx := MustGetFeatureCtx(ctx)
if err = selp.Envelope.SanityCheck(); err != nil && !featureCtx.Tolerate(err) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

featureCtx.TolerateEmptyCandidateName && errors.Cause(err) == action.ErrInvalidCanName shouldn't be hidden in a function of FeatureCtx.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see, I was thinking in the future may have similar case again, so add a Tolerate for this kind of special case

@dustinxie dustinxie merged commit 05e3ac4 into master Feb 24, 2025
4 checks passed
@dustinxie dustinxie deleted the emptycandname branch February 24, 2025 03:55
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.

failed to commit block 21910804
3 participants