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: load config error #1145

Merged
merged 7 commits into from
Jan 14, 2025
Merged

Conversation

JeyJeyGao
Copy link
Contributor

@JeyJeyGao JeyJeyGao commented Jan 14, 2025

Fix:

  • the LoadConfigOnce function forgets the error and return a nil config and nil error next time. Updated to use sync.OnceValues to keep the returned values.

Resolves #1144

Signed-off-by: Junjie Gao <[email protected]>
Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 72.38%. Comparing base (1118964) to head (77278ff).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
internal/cmd/flags.go 25.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1145      +/-   ##
==========================================
- Coverage   72.52%   72.38%   -0.14%     
==========================================
  Files          50       50              
  Lines        3126     3125       -1     
==========================================
- Hits         2267     2262       -5     
- Misses        667      670       +3     
- Partials      192      193       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

Can you re-implement LoadConfigOnce using sync.OnceValues?

@JeyJeyGao JeyJeyGao marked this pull request as draft January 14, 2025 06:45
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
Signed-off-by: Junjie Gao <[email protected]>
@JeyJeyGao JeyJeyGao marked this pull request as ready for review January 14, 2025 07:16
Signed-off-by: Junjie Gao <[email protected]>
shizhMSFT
shizhMSFT previously approved these changes Jan 14, 2025
Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@Two-Hearts Two-Hearts left a comment

Choose a reason for hiding this comment

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

Let's make

SetPflagSignatureFormat = func(fs *pflag.FlagSet, p *string) {
more elegant:

SetPflagSignatureFormat = func(fs *pflag.FlagSet, p *string) {
    config, err := configutil.LoadConfigOnce()
    if err != nil || config.SignatureFormat == "" {
	fs.StringVar(p, PflagSignatureFormat.Name, envelope.JWS, PflagSignatureFormat.Usage)
        return
    }

    // set signatureFormat from config
    fs.StringVar(p, PflagSignatureFormat.Name, config.SignatureFormat, PflagSignatureFormat.Usage)
}

Signed-off-by: Junjie Gao <[email protected]>
@JeyJeyGao
Copy link
Contributor Author

Let's make

SetPflagSignatureFormat = func(fs *pflag.FlagSet, p *string) {

more elegant:

SetPflagSignatureFormat = func(fs *pflag.FlagSet, p *string) {
    config, err := configutil.LoadConfigOnce()
    if err != nil || config.SignatureFormat == "" {
	fs.StringVar(p, PflagSignatureFormat.Name, envelope.JWS, PflagSignatureFormat.Usage)
        return
    }

    // set signatureFormat from config
    fs.StringVar(p, PflagSignatureFormat.Name, config.SignatureFormat, PflagSignatureFormat.Usage)
}

Updated.

Copy link
Contributor

@Two-Hearts Two-Hearts left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@shizhMSFT shizhMSFT left a comment

Choose a reason for hiding this comment

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

LGTM

@JeyJeyGao JeyJeyGao merged commit cd933da into notaryproject:main Jan 14, 2025
7 checks passed
@JeyJeyGao JeyJeyGao deleted the fix/load_config_error branch January 14, 2025 09:16
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.

Load config issue
3 participants